廢話大道理不多說? ? 推送前的準(zhǔn)備工作大致分為三個步驟? : 1间校、通知授權(quán)矾克,2、通知注冊憔足, 3胁附、獲取APNS Token
1酒繁、通知授權(quán) ?分別以 iOS8 ? ?iOS10 ? 為界限 ?
// iOS10 下需要使用新的 API
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) completionHandler:^(BOOL granted,NSError * _Nullable error ){
if (granted) {
NSLog(@"notification? center open success");
}else{
NSLog(@"notification? center open failed");
}}];
}else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationType myTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
2、通知注冊
通知注冊的方法在10中被保留控妻,不做修改州袒。
[[UIApplication sharedApplication] registerForRemoteNotifications];
3、獲取APNS Token
獲取Token的方法在10中被保留弓候,不做修改郎哭。由于單一使用極光作為遠(yuǎn)程推送,token提交部分只有極光的代碼菇存。
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
//? Apns注冊成功夸研,該方法沒有沒有變化。
//? 通過JPUSH上傳設(shè)備Token.
[JPUSHService registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[JPUSHService handleRemoteNotification:userInfo];
}
不好意思依鸥。實在受夠了這個在線版本的圖片上傳亥至。之后不好在貼圖。直接上代碼贱迟。大家湊合看吧姐扮。