iOS8 兼容 请求开启远程推送代码

来源:互联网 发布:软件开发就业情况 编辑:程序博客网 时间:2024/06/05 14:27
//register for push notificationif ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8){    [[UIApplication sharedApplication] registerForRemoteNotifications];    UIUserNotificationType types = UIUserNotificationTypeBadge                                                                                                                      | UIUserNotificationTypeSound | UIUserNotificationTypeAlert ;    UIUserNotificationSettings * setting =  [UIUserNotificationSettings settingsForTypes:types categories:nil];    [[UIApplication sharedApplication] registerUserNotificationSettings:setting];    NSLog(@"isIOS8");}else{    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];    NSLog(@"not isIOS8");}BOOL  bPushEnable = NO;if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8){    UIUserNotificationSettings * pushSetting =  [[UIApplication sharedApplication] currentUserNotificationSettings];    if (pushSetting)    {        UIUserNotificationType   pushType =  pushSetting.types;        NSLog(@"push type = %d", pushType);        if (pushType == UIUserNotificationTypeNone)        {            bPushEnable = NO;        }        else        {            bPushEnable = YES;        }    }}else{    UIRemoteNotificationType pushType = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];    NSLog(@"push type = %d", pushType);    if (pushType == UIRemoteNotificationTypeNone)    {        bPushEnable = NO;    }    else    {        bPushEnable = YES;    }}//如果不能推送if (bPushEnable == NO){    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[UtilsHelper getLocalizeString:@"text_push_notification_title"] message:[UtilsHelper getLocalizeString:@"text_push_notification_content"] delegate:self cancelButtonTitle:[UtilsHelper getLocalizeString:@"text_yes"] otherButtonTitles:nil, nil];    [alert show];}
0 0