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];

}

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容