我一直在使用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);
}
答案 0 :(得分:0)
如果版本是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();
}