Skip to content

Instantly share code, notes, and snippets.

@trinnguyen
Last active October 10, 2016 04:21
Show Gist options
  • Save trinnguyen/4a99a8a2ae6d834df114998b66bae123 to your computer and use it in GitHub Desktop.
Save trinnguyen/4a99a8a2ae6d834df114998b66bae123 to your computer and use it in GitHub Desktop.
Xamarin.iOS Register Push Notification with SDK 10
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
var center = UNUserNotificationCenter.Current;
center.RequestAuthorization(UNAuthorizationOptions.Sound | UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge, (bool arg1, NSError error) =>
{
InvokeOnMainThread(() =>
{
if (error == null)
{
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
System.Diagnostics.Debug.WriteLine("center.RequestAuthorization ERROR");
System.Diagnostics.Debug.WriteLine(error);
}
});
});
}
else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new Foundation.NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else {
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment