iOS-用户在“设置"中手动启用“推送通知"时的代理方法
我们知道,当在应用程序中通过系统对话框提示用户请求推送通知"权限时,如果他单击是",则将调用application:didRegisterForRemoteNotificationsWithDeviceToken:
;如果他单击否",则将application:didFailToRegisterForRemoteNotificationsWithError:
叫.
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.
如果用户单击否",随后又转到设置"并手动打开推送通知该怎么办?返回应用程序后,是否将触发某个委托方法?我想在用户在设置"中打开推送通知后立即执行一段代码,什么是最好的检测方法,而不必每次都在applicationDidBecomeActive上尝试重新注册?
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?
如果用户拒绝您的通知请求,则会不调用didFailToRegisterForRemoteNotificationsWithError:
,因为注册没有失败-事实并非如此.甚至没有尝试.
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.
成功注册远程通知并不意味着您实际上可以通知用户-因为您需要检查传递给didRegisterUserNotificationSettings:
的值,但是,如果您感兴趣的只是接收后台推送通知的功能那么didRegisterForRemoteNotificationsWithDeviceToken:
可能就足够了
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