How can I check if the user has enabled remote notifications on ios 9 or ios 10?
If the user has not allowed or clicked No I want to toggle a message asking if they want to enable notifications.
The key differentiator is that getting push notifications are the default for Android apps. For iOS, the user is prompted to allow notifications when they first open a new app, so the default is not getting push notifications for any given app.
Apple recommends to use UserNotifications
framework instead of shared instances. So, do not forget to import UserNotifications
framework. As this framework is new in iOS 10 it's really only safe to use this code in apps building for iOS10+
let current = UNUserNotificationCenter.current() current.getNotificationSettings(completionHandler: { (settings) in if settings.authorizationStatus == .notDetermined { // Notification permission has not been asked yet, go for it! } else if settings.authorizationStatus == .denied { // Notification permission was previously denied, go to settings & privacy to re-enable } else if settings.authorizationStatus == .authorized { // Notification permission was already granted } })
You may check official documentation for further information: https://developer.apple.com/documentation/usernotifications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With