Xamarin iOS Local Notifications无法正常工作

时间:2015-04-30 10:23:45

标签: ios xamarin notifications

我已经浏览了iOS本地通知的Xamarin演练:

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

我无法让它发挥作用。它构建正常,但ReceivedLocalNotification上的AppDelegate方法永远不会触发。我做错了什么?

1 个答案:

答案 0 :(得分:3)

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

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

将以下代码添加到FinishedLaunching类的AppDelegate方法中:

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);
}