检查推送通知注册:isRegisteredForRemoteNotifications Not Updating [英] Checking Push Notification Registration: isRegisteredForRemoteNotifications Not Updating

查看:919
本文介绍了检查推送通知注册:isRegisteredForRemoteNotifications Not Updating的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下方法保持返回相同的值:

The following method keeps returning the same value:

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];

每次运行此代码时,结果为YES。即使我进入设置应用并为我的应用设置推送通知为关闭,当上面的代码运行时,它的评估结果为是。

Every time this code runs, the results is YES. Even when I go into the "Settings" app and set push notifications to "off" for my app, when the code above runs, it evaluates to YES.

其他详细信息:
*我正在运行该应用程序,得到了一个拥有iOS 8.1.3
的iphone *我在Xcode 6.1中运行该应用程序并且我已将手机物理连接到我的机器上

Other details: * I'm running the app on got an iphone that has iOS 8.1.3 * I'm running the app in Xcode 6.1 and I've got the phone physically attached to my machine

知道为什么isRegisteredForRemoteNotifications的值不会改变?

Any idea why the value of "isRegisteredForRemoteNotifications" doesn't change?

推荐答案

因为即使用户选择退出,iOS 8也会注册设备并提供令牌。

Because iOS 8 does register the device and provides a Token even if the user opts out from pushes.

在这种情况下推送不会在推送时呈现给用户发送,但如果您的应用程序正在运行,它将获取有效负载,以便您可以在应用程序运行时更新它...

In that case pushes are not presented to the user when the push is sent, but if your app is running it gets the payload so you can update it when the app is running...

检查是否在iOS中启用了推送通知8你应该检查启用的用户通知类型:

To check if push notifications are enabled in iOS 8 you should check for the enabled user notification types:

- (BOOL)pushNotificationsEnabled {
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {
        UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
        return (types & UIUserNotificationTypeAlert);
    }
    else {
        UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        return (types & UIRemoteNotificationTypeAlert);
    }
}

这篇关于检查推送通知注册:isRegisteredForRemoteNotifications Not Updating的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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