代码如下:
//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];
}