ios 原生推送配置

来源:互联网 发布:淘宝营销战略论文 编辑:程序博客网 时间:2024/05/07 21:12

点击打开链接

点击打开链接

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 -outaps_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 -inkeyPush_Noenc.pem -certfilePush.certSigningRequest -name "aps_developer_identity" -outaps_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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 雅思成绩丢了怎么办 上网要求刷脸怎么办 高考选修考d怎么办 考研两门专业课怎么办 考研数学太难怎么办 考研英语不过线怎么办 英语差考研复试怎么办 高中被学校开除怎么办 bois密码忘记了怎么办 xp系统管理员账号停用怎么办 学业负担太重怎么办 小学生手册丢了怎么办 自己不会写论文怎么办 写论文很心慌怎么办 写论文没有词怎么办 亲人入了邪教怎么办 小孩脾气很倔怎么办 研究生读不下去怎么办 国外打工生活费不够怎么办 本科学位被追回怎么办 本科学位丢了怎么办 国外留学挂科怎么办 英国预科被劝退怎么办? 如果预科没合格怎么办 研究生学费太贵怎么办 澳洲移民配额用不完怎么办 去美国探亲怎么办签证 去伊朗的签证怎么办 房产证被偷了怎么办 打黑工被发现怎么办 几年前被犬咬没打针怎么办 对狂犬疫苗过敏怎么办 想去墨尔本留学怎么办 大学没交学费会怎么办 交学费收据丢了怎么办 上海浦东金科苑幼儿园统筹怎么办 红酒瓶塞掉了怎么办 红酒瓶塞丢了怎么办 收入证明没有公章怎么办 父母没工作怎么办签证 在温哥华怎么办新西兰签证