IOS IOS 8 的远程通知无法在后台运行
IOS remote notifications not working in background for IOS 8
我一直在使用 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);
}
如果版本为 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();
}
我一直在使用 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);
}
如果版本为 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();
}