检查推送通知注册:isRegisteredForRemoteNotifications Not Updating

Ben*_*ney 17 iphone ios

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

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
Run Code Online (Sandbox Code Playgroud)

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

其他细节:*我正在运行该应用程序,得到一个iOS 8.1.3的iPhone*我在Xcode 6.1中运行该应用程序,我已将手机物理连接到我的机器

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

Lef*_*ris 21

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

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

要检查iOS 8中是否启用了推送通知,您应检查启用的用户通知类型:

- (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);
    }
}
Run Code Online (Sandbox Code Playgroud)