【问题标题】:Xamarin iOS Local Notifications not workingXamarin iOS 本地通知不起作用
【发布时间】:2015-07-10 00:10:25
【问题描述】:

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

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

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

【问题讨论】:

  • 当通知触发时,您的应用是前台还是后台?如果您的应用在前台,ReceivedLocalNotification 方法只会触发。
  • @FormigaNinja,那么当app在后台时该用什么方法呢?

标签: ios xamarin notifications


【解决方案1】:

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

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

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

【讨论】:

  • 嗨,FormigaNinja。我已经在这里回答了我自己的问题,所以我认为我不能再将其标记为已接受 2 天是正确的吗?
  • 作为对此的扩展,如果您运行的设备不在 ios8 中,您添加的代码将引发错误,因此请将代码包装在 IOS 版本的标准检查中。
猜你喜欢
  • 1970-01-01
  • 2020-06-30
  • 2023-04-03
  • 1970-01-01
  • 2018-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多