IOS 远程通知在 IOS 8 的后台不起作用
Posted
技术标签:
【中文标题】IOS 远程通知在 IOS 8 的后台不起作用【英文标题】:IOS remote notifications not working in background for IOS 8 【发布时间】:2015-03-10 15:30:56 【问题描述】:我一直在使用 Xamarin.ios,最近遇到了当 Iphone/Ipad 处于后台时尝试接收远程通知负载的问题。 IOS 7 设备似乎在后台或前台工作。但是,对于 IOS 8 设备,只有在触摸警报横幅时才会调用 DidReceiveRemoteNotification。当未触摸警报横幅并且应用程序处于后台时,我需要能够获取有效负载。为什么 IOS 7 的远程通知在后台工作,而 IOS 8 却不能。我做错了什么?
if (UIDevice.CurrentDevice.SystemVersion [0] >= '8')
UIUserNotificationType types = UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert;
UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes (types, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
else
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge |
UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes);
【问题讨论】:
【参考方案1】:如果版本是 iOS 8 或更高版本,您需要调用 RegisterForRemoteNotifications 方法,如下所示:
if (UIDevice.CurrentDevice.SystemVersion [0] >= '8')
UIUserNotificationType types = UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert;
UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes (types, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
【讨论】:
以上是关于IOS 远程通知在 IOS 8 的后台不起作用的主要内容,如果未能解决你的问题,请参考以下文章