Xamarin.iOS 8 push notifications
March 30. 2015 0 Comments
- Posted in:
- iOS
- Azure
- Mobile
- Xamarin
- Xamarin.Forms
With iOS 8+ the way you register for push notifications has changed a bit. So if you want your app to continue receiving push notifications on iOS 8 and above you will need to adjust your registration to this:
var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Sound
| UIUserNotificationType.Alert | UIUserNotificationType.Badge, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
To continue supporting iOS7 and bellow you can still register as before or just use the lines bellow:
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Sound
| UIUserNotificationType.Alert | UIUserNotificationType.Badge, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
const UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert
| UIRemoteNotificationType.Badge
| UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
}
Conclusion
I stumbled over this one as I was following along the Azure push notification hub tutorial. Hope it will be of some help to you.