集成信鸽推送!!!

2015年9月17号,从上午11点开始,到下午6点06分,我发誓,这是我目前为止最最生气的一下午,所以我必须写一篇博客记录一下!!坑爹的腾讯,让我记住你!!!

我在外包公司干活,要做的就是集成个推送,原来用的都是百度啊,极光啊 这些三方推送,但是这回我们后台一定要用信鸽,我想反正都差不多嘛,用就用呗,结果各种坑爹。。。(怎么坑的 我就不说了。。心痛)

 

集成信鸽步骤:

1.而话不说 苹果官网 先弄俩证书 一个是development下的 一个是product的,注意一定要是带推送的那个证书奥。

2.添加手机设备,生成推送描述文件,这些步骤都和别的一样就不说了。

3.将生成的证书和配置文件都安装到自己的电脑上,然后在钥匙串导出.p12文件 一共俩 一个development 的 一个product的(注意前两次密码是给P12文件加密的,后一次是自己电脑的密码)

4.将.p12文件 转换为.pem文件 通过 终端命令行来执行:

openssl pkcs12 -in product.p12 -out product.pem -nodes

5.将生成的pem文件上传到 信鸽平台上(信鸽平台先申请一个应用)以上都有教程一步一步来不会有错(接下来就是见证坑爹的时刻)

6.代码集成,直接拷贝了啊 都是垃圾代码。

#pragma mark 信鸽推送

    //----------------------------------推送

    /**

     *  1. 向Apple Push Notification Service 发送UserId和AppId

     */

    if ([UIDevice currentDevice].systemVersion.doubleValue <= 8.0) { // 小于8.0的设备

        UIRemoteNotificationType type = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;

        [application registerForRemoteNotificationTypes:type];

        

    } else { // 高于8.0版本的设备

        

        

        //        // 通知类型声音 提示框

        //        UIUserNotificationType type = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;

        //

        //        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];

        //

        //        // 注册通知类型

        //        [application registerUserNotificationSettings:settings];

        //

        //        // 向用户申请申请试用通知

        //        [application registerForRemoteNotifications];

        [self registerPushForIOS8];

    }

    //    //初始化XG push信息

    [XGPush startApp:2200148110 appKey:@"IRR94W6M12DR"];

    

 -----------------------------上面这段写在appDelegate 启动的那个方法里面------

 

#pragma mark - 推送事件

 

#pragma mark ios8推送

- (void)registerPushForIOS8{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_

    

    //Types

    UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

    

    //Actions

    UIMutableUserNotificationAction *acceptAction = [[UIMutableUserNotificationAction alloc] init];

    

    acceptAction.identifier = @"ACCEPT_IDENTIFIER";

    acceptAction.title = @"Accept";

    

    acceptAction.activationMode = UIUserNotificationActivationModeForeground;

    acceptAction.destructive = NO;

    acceptAction.authenticationRequired = NO;

    

    //Categories

    UIMutableUserNotificationCategory *inviteCategory = [[UIMutableUserNotificationCategory alloc] init];

    inviteCategory.identifier = @"INVITE_CATEGORY";

    [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault];

    [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextMinimal];

    NSSet *categories = [NSSet setWithObjects:inviteCategory, nil];

    UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories];

    [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

    [[UIApplication sharedApplication] registerForRemoteNotifications];

#endif

}

#pragma mark  获得deviceToken时候调用

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{

    // 注册设备信息

    [XGPush registerDevice:deviceToken];

    NSLog(@"-----》deviceToken===%@", deviceToken);

}

#pragma mark 注册远程推送失败

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{

    NSLog(@"注册远程推送失败 ----> 错误%@",error);

}

#pragma mark  接收到远程推送

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

    NSLog(@"OK---->接收到=%@", [[userInfo objectForKey:@"aps"] objectForKey:@"content-available"]);

}

 #pragma mark  接收到远程推送(ios8以上)

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{

    NSLog(@"ios8---->%@", userInfo);

    if (userInfo) {

        completionHandler(UIBackgroundFetchResultNewData);

    }else

    {

        completionHandler(UIBackgroundFetchResultFailed);

    }

}

------------------拷贝完了吧?---------

按理说到此结束了,要我现在做 我也这么做,那就网页推吧 但是 你会发现推送的时候 偶尔会有apns cer error 这个就是腾讯那坑爹的网页的错误!!!!!!害死老子了  啥也不说了 想静静。。。。。

 

 

总结:如果以上都认认真真的配置好 千万别忘了所有依赖库的添加,然后推送的时候 一定要勾选 开发推送,主题要经常改变着推  你就会发现每条都成功了。

 

转载于:https://www.cnblogs.com/zhangguoliang1992/p/4817626.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值