美文网首页
集成极光推送

集成极光推送

作者: Stone_熊小叔 | 来源:发表于2017-06-26 17:07 被阅读0次

part 1 Appkey

极光注册应用


part 2 证书及环境

极光证书配置

最后生成需要的文件

part 3 代码部分

在项目didFinishLaunchingWithOptions调用[self configurationJiguangWithOption:launchOptions];即可

#pragma mark 极光推送<可直接拷贝到项目>
    
static NSString *JiguangAppKey = @"你在极光注册的key";
static NSString *channel = @"Publish channel";
    
-(void)configurationJiguangWithOption:(NSDictionary *)launchingOption{
    //极光
    //Required
    //notice: 3.0.0及以后版本注册可以这样写,也可以继续用之前的注册方式
    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
    entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        // 可以添加自定义categories
        // NSSet<UNNotificationCategory *> *categories for iOS10 or later
        // NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9
    }
    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
    
    // Optional
    // 获取IDFA
    // 如需使用IDFA功能请添加此代码并在初始化方法的advertisingIdentifier参数中填写对应值
    NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    
    // Required
    // init Push
    // notice: 2.1.5版本的SDK新增的注册方法,改成可上报IDFA,如果没有使用IDFA直接传nil
    // 如需继续使用pushConfig.plist文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。
    [JPUSHService setupWithOption:launchingOption appKey:JiguangAppKey
                          channel:channel
                 apsForProduction:NO
            advertisingIdentifier:advertisingId];
}
    
//注册APNs成功并上报DeviceToken
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"My token is: %@", deviceToken);
    /// Required - 注册 DeviceToken
    [JPUSHService registerDeviceToken:deviceToken];
}

//实现注册APNs失败接口
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    //Optional
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}
    
//添加处理APNs通知回调方法
    // iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    // Required
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
}
    
    // iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    // Required
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler();  // 系统要求执行这个方法
}
    
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
    // Required, iOS 7 Support
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

part 4 测试结果

真机运行结果

part 5 推送一个试试效果?

效果图

只是简单版本,后面有时间再增加自定义的

相关文章

  • 实现iOS收到推送消息后跳到指定的页面

    ########这里离线推送用的极光推送,集成推送这里就不做说明了,根据极光官方文档集成基本没有什么问题。 ###...

  • 极光推送集成开发

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

  • iOS-iOS10极光推送的使用

    1、首先先配置好推送证书,传到极光。极光推送->iOS证书设置指南极光推送->iOS SDK集成指南(XCode8...

  • iOS-极光推送的使用

    1、首先先配置好推送证书,传到极光。极光推送->iOS证书设置指南极光推送->iOS SDK集成指南(XCode8...

  • "_OBJC_CLASS_$_JPUSHService

    在集成极光推送的时候运行报错:

  • Android 推送跳转逻辑

    本文例子已极光推送为例,极光推送集成连接如下:https://docs.jiguang.cn/jpush/clie...

  • 极光后台推送响铃

    前言: 本教程不讨论极光推送的集成,请自行百度如何集成极光推送本教程适用于需要支持ios10以下的后台推送响铃对于...

  • 极光推送 集成 使用 Token Authentication

    iOS 设备集成推送,以前需要集成开发证书和生产证书,比较麻烦,现在极光推送集成了Token Authentica...

  • 集成极光推送

    1.登录极光官网,上传app 名,你会得到一个appKey ,这个很重要; 2.下载相应的配置文件,添加到你的项目...

  • 集成极光推送

    什么注册申请账号的流程都不提了,官网上有;下面主要介绍单模块项目和多模块项目下的集成方法: 1. 单模块 在 mo...

网友评论

      本文标题:集成极光推送

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