对于iOS> = 8,仅限
在我的AppDelegate中,我注册了用户通知,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSLog(@"didFinishLaunchingWithOptions called");
    // iOS >= 8.0
    // register to receive user notifications
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    ...
}
完成后,我注册远程通知如下:
- (void)application:(UIApplication *)application  didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    NSLog(@"didRegisterUserNotificationSettings called");
    //register to receive remote notifications
    [application registerForRemoteNotifications];
}
完成后,我会检查该应用是否已注册
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken called");
    BOOL pushNotificationOnOrOff = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; // always returns TRUE
}
但是应用程序始终指示启用了推送通知,即使用户已明确设置应用程序的远程通知功能(通过首次安装应用程序后显示的通知权限警报,或通过应用程序设置).
我已将应用程序的后台模式/远程通知设置为TRUE.我一直在使用开发证书编译的实际设备(通过USB电缆连接)进行调试.
求救,我已经和我斗争了好几个小时.
这似乎是一个错误,我也在iPhone 6,iOS 8.1.2上发现了相同的行为.
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]TRUE即使用户拒绝推送通知权限(通过警报视图)或通过手动禁用通知,也始终返回Settings.app > Notifications.
经过一些研究后,我发现如果您Background App Refresh启用了应用程序,那么[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]将始终返回TRUE.
当Background App Refresh设置为FALSE,然后[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]返回正确的值.
作为解决方法,您可以评估[[UIApplication sharedApplication] currentUserNotificationSettings].types以确定是否允许推送通知.
typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
    UIUserNotificationTypeNone    = 0,      // the application may not present any UI upon a notification being received
    UIUserNotificationTypeBadge   = 1 << 0, // the application may badge its icon upon a notification being received
    UIUserNotificationTypeSound   = 1 << 1, // the application may play a sound upon a notification being received
    UIUserNotificationTypeAlert   = 1 << 2, // the application may display an alert upon a notification being received
} NS_ENUM_AVAILABLE_IOS(8_0);
希望这可以帮助.