iOS-用户在“设置"中手动启用“推送通知"时的代理方法 [英] iOS - Delegate method when user turns on Push Notification manually in Settings

查看:117
本文介绍了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

这篇关于iOS-用户在“设置"中手动启用“推送通知"时的代理方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆