Skip to content

Instantly share code, notes, and snippets.

@codercampos
Last active September 17, 2018 00:44
Show Gist options
  • Save codercampos/adac9cbc6c7a10a0471424ac62dd1cc8 to your computer and use it in GitHub Desktop.
Save codercampos/adac9cbc6c7a10a0471424ac62dd1cc8 to your computer and use it in GitHub Desktop.
Ask for local notification permissions in AppDelegate
// Check for permissions
if (UIDevice.CurrentDevice.CheckSystemVersion (10, 0)) {
// Ask the user for permission to get notifications on iOS 10.0+
UNUserNotificationCenter.Current.RequestAuthorization (
UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound,
(approved, error) => {
if (approved) {
UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate ();
}
});
} else if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
// Ask the user for permission to get notifications on iOS 8.0+
var settings = UIUserNotificationSettings.GetSettingsForTypes (
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new NSSet ());
UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
}
using UserNotifications;
namespace LocalNotifications.iOS.Notifications
{
public class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate
{
public UserNotificationCenterDelegate()
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment