ios 原生推送配置

点击打开链接

点击打开链接

http://eric-gao.iteye.com/blog/1567777


1、将aps_developer_identity.cer转换成aps_developer_identity.pem格式


openssl x509 -in aps_developer_identity.cer -inform DER -out aps_developer_identity.pem -outform PEM  
 

 2、将p12格式的私钥转换成pem


openssl pkcs12 -nocerts -out Push_Noenc.pem -inPush.p12 


4、创建p12文件


openssl pkcs12 -export -in aps_developer_identity.pem -inkey Push_Noenc.pem -certfile Push.certSigningRequest -name " aps_developer_identity" -out aps_developer_identity.p12  
 
这样我们就得到了在.net或java等后台应用程序中使用的证书文件: aps_developer_identity.p12

接下来就要测试一下啦,是不是很激动~

为了测试证书工作的状况,我们可以使用“telnet gateway.sandbox.push.apple.com 2195”来检测一下,如果显示



则表示成功了。


 

然后,我们使用我们生成的证书和私钥来设置一个安全的链接去链接苹果服务器

在终端输入如下命令:openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem

需要输入密码(abc123 我们刚才所设置的)。

然后他会返回一系列的数据,这里我就粘贴一部分啦:


CONNECTED(00000003)

depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C

verify error:num=20:unable to get local issuer certificate

verify return:0

---

Certificate chain

。。。。。(省略)

。。。。。(省略)

。。。。。(省略)


    Start Time: 1416389389

    Timeout   : 300 (sec)

    Verify return code: 0 (ok)

---

测试就到这里啦。。。



------代码----

#pragma mark - 接受deviceToken



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

    

    __block NSString *token1 = [NSString stringWithFormat:@"%@", deviceToken];



    NSLog(@"My token is:%@", token1);

    

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        

        token1 = [token1 stringByReplacingOccurrencesOfString:@"<" withString:@""];

        token1 = [token1 stringByReplacingOccurrencesOfString:@">" withString:@""];

        

        [SANDBOXHELPER saveCoreInfoToSandBox:token1 withKey:kDeviceTokenInSandBox];

        

        NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithObject:token1 forKey:@"deviceToken"];

        

        if(getUserId && ![[getUserId stringValue] isEqualToString:@""]){//如果userID不为空

            

            [dic setObject:getUserId forKey:@"memberId"];

        }

        

        [[JSFAPI shareInstance] do_request:upload_device_token withData:dic withSuccessHandler:^(NSDictionary *json) {

            

            PYLog(@"%@",json);

            

        } fail:^(NSError *error) {

            

            PYLog(@"%@",error);

            

        }];

        

    });

    

    

}



- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{



    NSLog(@"My token is:");

    

}





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

{

    NSLog(@"Failed to get token, error: %@" , error);

}



#pragma mark - 接受到push



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

    

    PYLog(@"%@",userInfo);

    

    [UIApplication sharedApplication].applicationIconBadgeNumber++;

    

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:userInfo[@"aps"][@"alert"] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去看看", nil];

    

    [alert show];

    

    objc_setAssociatedObject(alert, &alertViewAndUserInfo, userInfo, OBJC_ASSOCIATION_RETAIN);



}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值