iOS极光推送部分

作者: 风外杏林香 | 来源:发表于2016-12-08 18:52 被阅读70次

研究了下极光推送,最恶心的部分莫过于一系列证书的配置,
1、注意下p12的导出,特别需要注意,
正确方式是这样的

正确导出方式,直接导出
错误方式是这样的
错误方式,打开后导出
2、xcode 的配置

3、导入极光推送sdk,同时,添加依赖库
  CFNetwork.framework
  CoreFoundation.framework
  CoreTelephony.framework
  SystemConfiguration.framework
  CoreGraphics.framework
  Foundation.framework
  UIKit.framework
  Security.framework
  libz.tbd (Xcode7以下版本是libz.dylib)
  AdSupport.framework (获取IDFA需要;如果不使用IDFA,请不要添加)
  UserNotifications.framework (Xcode8及以上)
  libresolv.tbd (JPush 2.2.0及以上版本需要, Xcode7以下版本是libresolv.dylib)

真机编译,没报错,好的接下来开始敲代码
4、在AppDelegate.m里面添加 JPUSHRegisterDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
        //iOS10以上
        JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
        entity.types = UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound;
        [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];

    } else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        //iOS8以上可以添加自定义categories
        [JPUSHService registerForRemoteNotificationTypes:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) categories:nil];
    } else {
        //iOS8以下categories 必须为nil
        [JPUSHService registerForRemoteNotificationTypes:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)categories:nil];
        
    }
    
    BOOL isProduction = NO;// NO为开发环境,YES为生产环境
    //广告标识符
    NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    //Required(2.1.5版本的SDK新增的注册方法,改成可上报IDFA,如果没有使用IDFA直接传nil
    [JPUSHService setupWithOption:launchOptions appKey:APP_KEY
                          channel:nil
                 apsForProduction:isProduction
            advertisingIdentifier:advertisingId];
    //此处设置当点击icon时候进入app 销毁icon badge
    NSInteger bagValue = [UIApplication sharedApplication].applicationIconBadgeNumber;
    NSLog(@"bagValue -- %ld", bagValue);
    if (bagValue != 0) {
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
        [JPUSHService setBadge:0];
        [[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
        [[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];
        
    }    
    return YES;
}
#pragma mark -- 注册 DeviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [JPUSHService registerDeviceToken:deviceToken];
}
#pragma mark -- JPUSHRegisterDelegate
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger options))completionHandler
{
    // Required
    NSDictionary * userInfo = notification.request.content.userInfo;
    NSLog(@"userInfo -- %@", userInfo);
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]
        ]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler(UNNotificationPresentationOptionAlert); // 需要执这个方法,选择是否提醒户,有Badge、Sound、Alert三种类型可以选择设置
}

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
{
    // Required
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    NSLog(@"00000userInfo -- %@", userInfo);
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler(); // 系统要求执行这个方法
}
#pragma mark -- iOS 7 远程请求
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}
#pragma mark -- iOS 6 或者以下远程请求
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [JPUSHService handleRemoteNotification:userInfo];
}

接下来,我们从极光后台,推送一条消息过来,打印出来的userInfo

userInfo -- {
    "_j_msgid" = 2929855611;
    aps =     {
        alert = "775wode ";
        badge = 1;
        sound = default;
    };
}

我们看到 badge = 1,同时受到的消息为 alert = "775wode"
好的,我们再发送一条消息

有比较就有发现
badge 值一直为1,同时,我们发送了俩条消息,但是icon角标上面一直显示为1
这样解决,我们直接在极光的后台设置badge值为 +1这样每次发送消息的时候,在之前的基础上面加1,数量变正常
直接后台设置咯
以上,就是集成极光推送发送远程通知的内容,个人认为,集成不难,难的是,集成之前各种证书的配置,生产环境,开发环境,各种烦躁,希望大家一起加油!!!

相关文章

  • iOS极光推送部分

    研究了下极光推送,最恶心的部分莫过于一系列证书的配置,1、注意下p12的导出,特别需要注意,正确方式是这样的 真机...

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

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

  • iOS-iOS10极光推送的使用

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

  • iOS-极光推送的使用

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

  • 极光推送集成开发

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

  • iOS —— 极光推送和极光IM

    前言 (环境:iOS12.0、极光推送SDK3.1.0、极光IM3.7.0) 写iOS 推送(苹果原生态)时,笔者...

  • 使用苹果原生APNS和后端推送工具Easy APNs Provi

    最近研究苹果原生apns,极光推送在此不详细解释了,具体查看极光文档极光推送传送门 原生APNS,iOS 代码如下...

  • 环信消息推送

    一,关于推送 之前做过 极光 APNS 个推的 推送 : 这里说下 极光推送是比较 适合用在 iOS 端和 安卓端...

  • iOS 推送参考文档

    1、ios 消息推送证书设置和整理(备忘)2、iOS 远程推送APNS从0至发布-极光推送& 真机测试篇3、iOS...

  • IOS 推送 (极光推送)

    今天朋友说到推送,因为以前也没做过,就跟着看了看极光的推送.(自己的每一步,很详细,很啰嗦..大神就不用看了......

网友评论

    本文标题:iOS极光推送部分

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