iOS的推送通知设置 - 权限被拒绝VS权限从未要求 [英] iOS Push Notification Settings - Denied Permission vs Permission Never Requested

查看:589
本文介绍了iOS的推送通知设置 - 权限被拒绝VS权限从未要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能的案件来区分,其中

Is it possible to differentiate between the cases where


  1. 在iOS用户已经明确拒绝用户通知权限和

  2. 在iOS用户从未提示许可?

我的情况:在过去,我已经提示用户通知许可,但从来没有保持跟踪请求的自己。后来,我不再试图注册任何通知设置。现在,我想重新引入用户通知。

My situation: In the past, I've prompted for user notification permission, but never kept track of requests myself. Later, I stopped attempting to register any notification settings. Now, I'd like to re-introduce user notifications.

在App一个显著的事件后,我的计划是,以显示某种UI的解释选择加入用户通知的好处。但是,如果用户已经下降,我会preFER表明,可以带他们到Settings.app一个独立的UI。

After a significant event in the App, my plan is to display some sort of UI that explains the benefit of opting in to user notifications. However, if the user has already declined, I'd prefer to show a separate UI that can take them into Settings.app.

目前,我使用 - [UIApplication的currentUserNotificationSettings] 来抓取当前设置,但看来这返回 UIUserNotificationTypeNone 为双方的上述情况。

Currently, I'm using -[UIApplication currentUserNotificationSettings] to grab the current settings, but it appears that this returns UIUserNotificationTypeNone for both of the above described cases.

推荐答案

我个人还没有找到一种方法,通过iOS SDK中的快速查询,以确定这一点。

Personally I haven't found a way to determine this via a quick query of the iOS SDK.

不过,我已经能够跟踪这个自己录制时, - [UIApplication的应用:didRegisterUserNotificationSettings:] 被调用。

However I have been able to track this myself recording when -[UIApplication application:didRegisterUserNotificationSettings:] is called.

在iOS的调用这个方法,可以确保用户已被提示输入用户通知的权限和拥有(重要)接受或否认。

When iOS calls this method, you can be sure the user has been prompted for user notification permissions and has (importantly) either accepted or denied it.

当这种情况发生时,你可以在以后检查此值,以确定如果提示已经或之前未显示存储。

Storing when this occurs you can later check this value to determine if the prompt has been shown before or not.

举例code:

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"ABHasPromptedForUserNotification"];
    //... your other notification registration handling... 
}

- (BOOL)hasPromptedForUserNotification {
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"ABHasPromptedForUserNotification"];
}

FYI:我找到了preferable设置ABHasPromptedForUserNotification作为在真 - [UIApplication的应用:didRegisterUserNotificationSettings: ] ,而不是当我打电话 - [UIApplication的registerForRemoteNotifications] 在某些情况下,用户可根据需要显示的提示多次。如果用户的背景发生这种情况的应用程序,或者需要一个电话。在这种情况下,迅速将iOS的被隐藏,并再次显示,如果下次呼叫时间 - [UIApplication的registerForRemoteNotifications] 。在委托设置此设置避免了思想的用户已被提示前,不会在这些边缘情况再次提示。

FYI: I've found it preferable to set "ABHasPromptedForUserNotification" as true in the in -[UIApplication application:didRegisterUserNotificationSettings:] rather than when I call -[UIApplication registerForRemoteNotifications] as in some situations the user can be shown the prompt multiple times. This can happen if the user backgrounds the app, or takes a call. In these cases the prompt will be hidden by iOS, and shown again if next time you call -[UIApplication registerForRemoteNotifications]. Setting this setting in the delegate avoids thinking the user has been prompted before and won't be prompted again in these edge cases.

这篇关于iOS的推送通知设置 - 权限被拒绝VS权限从未要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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