Reputation: 775
User install the app and tapped "Don't allow" and denied push notifications. And when the app is active, user go to system settings and grant push notification and then go back to the application.
How can I detect that settings notification permission was changed when the application is going to active and call register for push notifications?
Upvotes: 6
Views: 12032
Reputation: 572
You can check it AppDelegates's didBecomeActive event by using same code. didBecomeActive event is called each time when app comes from background state to foreground state.
let center = UNUserNotificationCenter.current()
center.getNotificationSettings { (settings) in
if(settings.authorizationStatus == .authorized) {
print("Push notification is enabled")
} else {
print("Push notification is not enabled")
}
}
Upvotes: 2
Reputation: 8904
For iOS 10.0 and later, you can use UNUserNotificationCenter
.
You need to import this
import UserNotifications
and then user following to get notificAtion settings of your app.
let center = UNUserNotificationCenter.current()
center.getNotificationSettings { (settings) in
if(settings.authorizationStatus == .authorized) {
print("Push notification is enabled")
} else {
print("Push notification is not enabled")
}
}
Upvotes: 4