Last active
October 10, 2016 04:21
-
-
Save trinnguyen/4a99a8a2ae6d834df114998b66bae123 to your computer and use it in GitHub Desktop.
Xamarin.iOS Register Push Notification with SDK 10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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