4
votes

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?

2
AFAIK there isn't any continuous service that you can use to detect this change in real time. There is a good discussion here - stackoverflow.com/questions/1535403/… .Best way is to detect the enabled types for PUSH when required and request permission when you really need to seek user permission for allowing PUSH. Also what i recall is that if user denies this prompt three times in a row then you can not show this prompt un till the next install (Please verify for exact number of times and if this behavior is still valid.)Rahul Sharma
Thank you, that link is very helpful. As for your question of prompting the dialog, here is Apple's answer: link @RahulSharmaSeaJelly

2 Answers

2
votes

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

0
votes

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) {
}