因為ios8.0前后不一樣,所以就隨筆記下,這些都是項目用過的
/**注冊用戶通知*/
- (void)registerUserNotification {
/*
注冊通知(推送)
申請App需要接受來自服務(wù)商提供推送消息
*/
//判讀系統(tǒng)版本是否是“iOS 8.0”以上
if([[[UIDevicecurrentDevice]systemVersion]floatValue] >=8.0||
[UIApplicationinstancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
//定義用戶通知類型(Remote.遠(yuǎn)程- Badge.標(biāo)記Alert.提示Sound.聲音)
UIUserNotificationTypetypes =UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
//定義用戶通知設(shè)置
UIUserNotificationSettings*settings = [UIUserNotificationSettingssettingsForTypes:typescategories:nil];
//注冊用戶通知-根據(jù)用戶通知設(shè)置
[[UIApplicationsharedApplication]registerUserNotificationSettings:settings];
[[UIApplicationsharedApplication]registerForRemoteNotifications];
}else{// iOS8.0以前遠(yuǎn)程推送設(shè)置方式
//定義遠(yuǎn)程通知類型(Remote.遠(yuǎn)程- Badge.標(biāo)記Alert.提示Sound.聲音)
UIRemoteNotificationTypemyTypes =UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
//注冊遠(yuǎn)程通知-根據(jù)遠(yuǎn)程通知類型
[[UIApplicationsharedApplication]registerForRemoteNotificationTypes:myTypes];
}
}