Xamarin iOS 本地通知不工作
Xamarin iOS Local Notifications not working
我已经完成了 iOS 本地通知的 Xamarin 演练:
而且我无法让它工作。它构建良好,但是 AppDelegate
上的 ReceivedLocalNotification
方法永远不会触发。我做错了什么?
如果您使用的是 iOS 8,您还需要注册您的应用才能接收通知,如下所述:
将以下代码添加到 AppDelegate
class 的 FinishedLaunching
方法中:
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) {
UIUserNotificationType notificationTypes = UIUserNotificationType.Alert |
UIUserNotificationType.Badge |
UIUserNotificationType.Sound;
var userNoticationSettings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, new NSSet(new string[] {}));
UIApplication.SharedApplication.RegisterUserNotificationSettings (userNoticationSettings);
}
我已经完成了 iOS 本地通知的 Xamarin 演练:
而且我无法让它工作。它构建良好,但是 AppDelegate
上的 ReceivedLocalNotification
方法永远不会触发。我做错了什么?
如果您使用的是 iOS 8,您还需要注册您的应用才能接收通知,如下所述:
将以下代码添加到 AppDelegate
class 的 FinishedLaunching
方法中:
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) {
UIUserNotificationType notificationTypes = UIUserNotificationType.Alert |
UIUserNotificationType.Badge |
UIUserNotificationType.Sound;
var userNoticationSettings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, new NSSet(new string[] {}));
UIApplication.SharedApplication.RegisterUserNotificationSettings (userNoticationSettings);
}