美文网首页
ios 10 推送注册更新设置方法

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

作者: 守护浪漫的小香樟 | 来源:发表于2017-12-20 13:04 被阅读0次

    废话大道理不多说    推送前的准备工作大致分为三个步骤  : 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 推送注册更新设置方法

          本文链接:https://www.haomeiwen.com/subject/jswwmttx.html