简体   繁体   中英

iOS - Delegate method when user turns on Push Notification manually in Settings

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM