Reputation: 1746
We know that when a user is prompted with the system dialog in an app asking for Push Notification permission, if he clicks "YES" then application:didRegisterForRemoteNotificationsWithDeviceToken:
will be called, if he clicks "NO" then application:didFailToRegisterForRemoteNotificationsWithError:
will be called.
What if the user clicks "NO", then later on goes to Settings and manually turns on push notifications? Upon returning to the app, will a certain delegate method be triggered? I would like to execute a block of code as soon as the user turns on push notifications in Settings, what is the best way to detect that, without trying to register again every time on applicationDidBecomeActive?
Upvotes: 4
Views: 2264
Reputation: 812
once user click on allow or don't allow on push notification popup, below delegate will call for sure on both options.
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
}
Upvotes: 0
Reputation: 114826
If the user denies your request for notifications then didFailToRegisterForRemoteNotificationsWithError:
is not called, because registration didn't fail - it wasn't even attempted.
If the user changes the permissions in the settings app then you will receive a call to didRegisterForRemoteNotificationsWithDeviceToken:
either the next time your app is launched or when your app returns to the foreground if it is in the background.
The successful registration of remote notifications doesn't mean that you can actually notify the user - for that you need to check the value passed to didRegisterUserNotificationSettings:
, however if all you are interested in is the ability to receive background push notifications then didRegisterForRemoteNotificationsWithDeviceToken:
may be sufficient
Upvotes: 2