在我的Xamarin.iOS项目的AppDelegate
类中,我有方法:
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
Hub = new SBNotificationHub(Constants.ListenConnectionString, Constants.NotificationHubName);
Hub.UnregisterAllAsync (deviceToken, (error) => {
if (error != null)
{
System.Diagnostics.Debug.WriteLine("Error calling Unregister: {0}", error.ToString());
return;
}
NSSet tags = null; // create tags if you want
Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) => {
if (errorCallback != null)
System.Diagnostics.Debug.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
});
});
}
如何从我的PCL项目中调用它?
答案 0 :(得分:1)
a)在PCL项目中创建一个接口:
int[] n = {1,6,3,7,6,6,7,1};
int sum = 0;
outer:
for (int i = 0; i < n.length; i++) {
if (n[i] == 6) {
for (int j = i + 1; j < n.length; j++) {
if (n[j] == 7) {
i = j;
continue outer;
}
}
}
sum += n[i];
}
System.out.println(sum); // 2
b)创建一个将在您的iOS项目中实现此接口的类,记住要用所需的属性装饰该类:
namespace YourNamespace.Interfaces
{
public interface IRemoteNotifications
{
void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken);
}
}
c)使用依赖服务从PCL项目中调用自定义实现,以找到接口实现。
[assembly: Dependency(typeof(RemoteNotifications))]
namespace YourNamespace.iOS.DependencyService
{
public class RemoteNotifications : IRemoteNotifications
{
public void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
// Place your custom logic here
}
}
}
d)执行您的逻辑。
这就是您所需要的。