1. 程式人生 > >ios (推送之遠端推送)升級成ios8系統之後有些程式接收不到遠端推送

ios (推送之遠端推送)升級成ios8系統之後有些程式接收不到遠端推送

維護一個程式,當手機升級到ios8之後就不能接收到遠端推送,顯示註冊失敗,查了下資料,原來是沒有獲取使用者許可,加了個方法試了下,ok

if ([[[UIDevice currentDevice]systemVersion ]integerValue] >= 8) {
        
        UIUserNotificationSettings*setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];
        [application registerUserNotificationSettings:setting];
        [application registerForRemoteNotifications];
        
    }else{
        
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
        
    }

系統版本不同所用的註冊方法也是不一樣的,下面是蘋果sdk給出的說明:

- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types NS_DEPRECATED_IOS(3_0, 8_0, <span style="color:#FF0000;">"Please use registerForRemoteNotifications and registerUserNotificationSettings: instead"</span>);