I have been using Xamarin.IOS, and I recently came across the problem of trying to receive a remote notification payload when the Iphone/Ipad is in background. IOS 7 devices seem to be working when in background or in forground. However, for the IOS 8 devices the DidReceiveRemoteNotification is only called if the alert banner is touched. I need to be able to get the payload when alert banner is not touched and application is in background. Why are remote notifications working in background for IOS 7 but not for IOS 8. What could I be doing wrong?
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);
}
You need to call the RegisterForRemoteNotifications method if the version is iOS 8 or greater like so:
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.