Sea*_*ser 22 push-notification apple-push-notifications ios ios-permissions
是否有可能区分其中的情况
我的情况:过去,我已经提示用户通知权限,但我从未跟踪过请求.后来,我停止尝试注册任何通知设置.现在,我想重新介绍用户通知.
在应用程序中发生重大事件后,我的计划是显示某种UI,以解释选择加入用户通知的好处.但是,如果用户已拒绝,我宁愿显示一个可以将其带入Settings.app的单独UI.
目前,我正在使用-[UIApplication currentUserNotificationSettings]
抓取当前设置,但似乎这会返回UIUserNotificationTypeNone
上述两种情况.
Gle*_*n T 24
就个人而言,我还没有找到通过快速查询iOS SDK来确定这一点的方法.
但是,当我-[UIApplication application:didRegisterUserNotificationSettings:]
被调用时,我能够自己跟踪这个记录.
当iOS调用此方法时,您可以确保已提示用户提供用户通知权限,并且(重要的)已接受或拒绝该用户.
在发生这种情况时进行存储,您可以稍后检查此值以确定是否先前已显示提示.
示例代码:
- (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"];
}
Run Code Online (Sandbox Code Playgroud)
仅供参考:我发现最好"ABHasPromptedForUserNotification"
在in中设置为true -[UIApplication application:didRegisterUserNotificationSettings:]
而不是在我调用时,-[UIApplication registerForRemoteNotifications]
因为在某些情况下用户可以多次显示提示.如果用户为应用程序提供背景或接听电话,则会发生这种情况.在这些情况下,iOS会隐藏提示,如果您下次打电话,则会再次显示-[UIApplication registerForRemoteNotifications]
.在委托中设置此设置可以避免认为之前已提示用户,并且在这些边缘情况下不会再次提示用户.
归档时间: |
|
查看次数: |
3521 次 |
最近记录: |