注册用户通知

因为ios8.0前后不一样,所以就随笔记下,这些都是项目用过的

/**注册用户通知*/

- (void)registerUserNotification {

/*

注册通知(推送)

申请App需要接受来自服务商提供推送消息

*/

//判读系统版本是否是“iOS 8.0”以上

if([[[UIDevicecurrentDevice]systemVersion]floatValue] >=8.0||

[UIApplicationinstancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {

//定义用户通知类型(Remote.远程- Badge.标记Alert.提示Sound.声音)

UIUserNotificationTypetypes =UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;

//定义用户通知设置

UIUserNotificationSettings*settings = [UIUserNotificationSettingssettingsForTypes:typescategories:nil];

//注册用户通知-根据用户通知设置

[[UIApplicationsharedApplication]registerUserNotificationSettings:settings];

[[UIApplicationsharedApplication]registerForRemoteNotifications];

}else{// iOS8.0以前远程推送设置方式

//定义远程通知类型(Remote.远程- Badge.标记Alert.提示Sound.声音)

UIRemoteNotificationTypemyTypes =UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;

//注册远程通知-根据远程通知类型

[[UIApplicationsharedApplication]registerForRemoteNotificationTypes:myTypes];

}

}

你可能感兴趣的:(注册用户通知)