美文网首页
极光推送

极光推送

作者: LennonLin | 来源:发表于2016-11-25 09:31 被阅读13次
  • 照着文档来就只缺一个获取devicetoken,上代码呗

#pragma mark - 极光推送

- (void)JPush:(NSDictionary *)launchOptions {
    [self JPushAddAPNs];
    [self JPushInit:launchOptions];
}

// 添加初始化APNs代码
- (void)JPushAddAPNs {
    
    if (GETCURRENTVERSION >= 10.0) {
        JPUSHRegisterEntity *entity = [[JPUSHRegisterEntity alloc] init];
        entity.types = UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound;
        [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
    } else if (GETCURRENTVERSION >= 8.0) {
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
    } else {
        // 不在支持8.0以下
    }
}

// 初始化JPUsh代码 设置的是开发模式
- (void)JPushInit:(NSDictionary *)launchOptions {
    // 获取IDFA 没有可直接传nil
    NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    
    // channel是分发路径 一个是什么模式 adverid可有可无
   [JPUSHService setupWithOption:launchOptions appKey:JPushAppKey channel:@"" apsForProduction:NO advertisingIdentifier:advertisingId];
}

// 注册APNs失败接口
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    //Optional
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}

// 获取deviceToken  环信也需要在这儿获取给SDK
/*****************这个在极光的文档里并没有********************/
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    [JPUSHService registerDeviceToken:deviceToken];
}

#pragma mark - JPUSHRegisterDelegate

// iOS 10 Support 提示后台全部包在一个数组里 这个安卓可以成功iOS可能存在问题 但是是后台的错
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    NSDictionary *userInfo = notification.request.content.userInfo;
    if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler(UNNotificationPresentationOptionAlert); // 系统要求执行额这个方法 选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
}

/**********     文档也没有 但是Appdelegate有提示     ***************/
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler();  // 系统要求执行这个方法
}

// iOS 7
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

// 环信接受到的推送 极光接收的推送
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [JPUSHService handleRemoteNotification:userInfo];
}

相关文章

  • 极光推送

    极光推送视频地址,非常详细的极光推送视频 极光推送

  • 极光推送

    极光推送 tagprivate void initJpush() {//TODO 极光推送// JPushInte...

  • 极光推送进行远程推送

    借阅:极光推送进行远程推送 怎么使用极光推送进行远程推送 在极光官网注册极光推送创建一个应用在应用配置中导入两个证...

  • ios极光推送

    第一次使用极光推送,在这里把极光推送的步骤说一下,省的以后再次用到极光推送的时候,给忘了,其实,极光推送不难...

  • 【知识总结】(2)远程推送

    推送SDK:极光推送 后台点击推送: iOS 10 以下收到推送点击触发 iOS 10 以上触发: 极光推送中使用...

  • 2018年功能模块沉淀

    一、推送模块 1.极光推送 文档:https://www.jiguang.cn/push备注:极光推送包括普通推送...

  • 极光推送(二)——推送的使用

    前言 在极光推送(一)——配置中讲过了极光推送的配置,这节讲讲极光推送的使用参考文档极光官网 下面以我写的demo...

  • 极光推送集成开发

    1.极光推送集成与设置 极光推送地址①注册极光推送账号。②在应用管理内按照步骤创建APP。③找到“文档——iOS—...

  • Flutter开发 集成极光推送

    Flutter推送 极光推送Flutter版本 最近研究Flutter推送,在网上找了很多资料,发现极光推送竟然有...

  • 极光征文 | 我与极光的缘分

    极光征文 | 我与极光的缘分 首先简单介绍下极光推送;极光推送(JPush)是独立的第三方云推送平台,致力于为全球...

网友评论

      本文标题:极光推送

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