Xamarin iOS 本地通知不工作

Xamarin iOS Local Notifications not working

我已经完成了 iOS 本地通知的 Xamarin 演练:

http://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/ios/local_notifications_in_ios_walkthrough/

而且我无法让它工作。它构建良好,但是 AppDelegate 上的 ReceivedLocalNotification 方法永远不会触发。我做错了什么?

如果您使用的是 iOS 8,您还需要注册您的应用才能接收通知,如下所述:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1

将以下代码添加到 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);
}