我怎么知道,如果用户没有允许推送通知 [英] How do I know if user didn't allow push notifications
问题描述
我看了<一个href=\"http://stackoverflow.com/questions/19704501/what-is-the-callback-method-if-you-click-dont-allow-in-push-notification-popu\">this问题但如果有一个明确的答案不明白。
I saw this question but didn't understand if there is a clear answer.
我可以告诉大家,如果用户pressed不允许的第二次发射的应用程序通过设置一个标志:
I can tell if the user pressed "don't allow" on the SECOND launch of the app by setting a flag:
BOOL didRequest = [[NSUserDefaults standardUserDefaults] boolForKey:@"DidRequestPushNotifications"];
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone && didRequest)
{
[self showAlertToUserToEnableRemoteNotificationsOnDeviceInSettings];
}
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"DidRequestPushNotifications"];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
但对于首批推出的应用程序 - 对成功和失败两种委托方法不叫,这意味着,有没有办法知道肯定
But for the first launch of the app - both delegate methods for success and failure aren't called and that means that there is no way to know for sure.
任何变通?
推荐答案
在除已链接的答案,一个工作,我身边能想到的是,一旦用户成功注册了推,可以存储在设备令牌 NSUserDefaults的
。
In addition to the answer you have linked, a work around I can think of is, once user successfully registered for pushes, You can store the device token in the NSUserDefaults
.
这样你可以检查用户设置的值无
或没有。
This way you can check if the value of that user setting is nil
or not.
这篇关于我怎么知道,如果用户没有允许推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!