Last active
September 17, 2018 00:44
-
-
Save codercampos/adac9cbc6c7a10a0471424ac62dd1cc8 to your computer and use it in GitHub Desktop.
Ask for local notification permissions in AppDelegate
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
// 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); | |
} |
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
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