您的位置:首页 > 移动开发 > IOS开发

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

2015-04-10 11:19 204 查看
//register for push notification
if ([[[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];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: