iOS - 当用户在设置中手动打开推送通知时的委托方法 [英] iOS - Delegate method when user turns on Push Notification manually in Settings

查看:27
本文介绍了iOS - 当用户在设置中手动打开推送通知时的委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,当用户在应用程序中通过系统对话框提示请求推送通知权限时,如果他点击是",则 application:didRegisterForRemoteNotificationsWithDeviceToken: 将被调用,如果他点击"NO" 然后 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: 不会被调用,因为注册没有't 失败 - 甚至没有尝试过.

If the user denies your request for notifications then didFailToRegisterForRemoteNotificationsWithError: is not called, because registration didn't fail - it wasn't even attempted.

如果用户更改了设置应用程序中的权限,那么您将在下次启动应用程序时或当您的应用程序返回前台时收到对 didRegisterForRemoteNotificationsWithDeviceToken: 的调用.背景.

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天全站免登陆