ios 10 推送注册更新设置方法

废话大道理不多说    推送前的准备工作大致分为三个步骤  : 1、通知授权,2、通知注册, 3、获取APNS Token


1、通知授权  分别以 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中被保留,不做修改。由于单一使用极光作为远程推送,token提交部分只有极光的代码。

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {

//  Apns注册成功,该方法没有没有变化。

//  通过JPUSH上传设备Token.

[JPUSHService registerDeviceToken:deviceToken];

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

[JPUSHService handleRemoteNotification:userInfo];

}

不好意思。实在受够了这个在线版本的图片上传。之后不好在贴图。直接上代码。大家凑合看吧。

你可能感兴趣的:(ios 10 推送注册更新设置方法)