iOS 8 enabled device not receiving PUSH notifications after code update

后端 未结 8 2503
陌清茗
陌清茗 2020-11-27 03:45

I recently upgraded one of my test iphones to iOS 8 and then upgraded the PUSH registration code as below (using xCode 6)

-(BOOL)hasNotificationsEnabled {

          


        
8条回答
  •  醉话见心
    2020-11-27 04:10

    Runtime and old compiler safe options ... if you run in old xcode (5.0 or earlier)

        // changes of API in iOS 8.0
    - (void) registerForPushNotification
    {
        NSLog(@"registerForPushNotification");
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
        {
    
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0 //__IPHONE_8_0 is not defined in old xcode (==0). Then use 80000
    
            NSLog(@"registerForPushNotification: For iOS >= 8.0");
    
            [[UIApplication sharedApplication] registerUserNotificationSettings:
                [UIUserNotificationSettings settingsForTypes:
                    (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
                                                  categories:nil]];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
    #endif
        } else {
            NSLog(@"registerForPushNotification: For iOS < 8.0");
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
             (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
        }
    }
    

提交回复
热议问题