我怎么知道用户是否不允许推送通知 [英] How do I know if user didn't allow push notifications

查看:74
本文介绍了我怎么知道用户是否不允许推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了 这个问题但不明白是否有明确的答案.

I saw this question but didn't understand if there is a clear answer.

我可以通过设置一个标志来判断用户是否在第二次启动应用时按下了不允许":

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.

这样您就可以检查该用户设置的值是否为nil.

This way you can check if the value of that user setting is nil or not.

这篇关于我怎么知道用户是否不允许推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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