iOS推送大全
来源:互联网 发布:core java 9 中文版 编辑:程序博客网 时间:2024/05/08 04:06
无论是iPhone客户端和APNS,还是Provider和APNS,都需要通过证书进行连接。
下面我介绍一下几种用到的证书。
一、CSR文件
1、生成Certificate Signing Request(CSR)
2、填写你的邮箱和常用名称,并选择保存到硬盘。
点击继续:
这样就在本地生成了一个Push.certSigningRequest文件。
二、p12文件
1、导出密钥。
2、输入你的密码。
这样就生成了一个Push.p12文件。
三、SSL certificate文件
1、用你付过费的帐号登录到iOS Provisioning Portal,并新建一个App ID,这个过程可以参考:iOS应用的真机调试,这样就会生成下面这条记录:
2、点击右侧的Configure:
3、点击Development Push SSL Certificate一行后的Configure:
4、点击Continue:
5、选择前面生成好的Push.certSigningRequest文件,点击Generate,出现如下所示的页面:
6、点击Continue:
7、点击Download,并将文件命名为aps_developer_identity.cer。
8、点击Done,你会发现状态变成了Enabled:
注意:有的App ID的Apple Push Notification service列是灰色的,并且不允许使用Configure按钮,这是因为APNS不支持带通配符的App ID。
到现在为止,我们已经生成了三个文件:
1、Push.certSigningRequest
2、Push.p12
3、aps_developer_identity.cer
在项目的AppDelegate中的didFinishLaunchingWithOptions方法中加入下面的代码:
- [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
通过registerForRemoteNotificationTypes方法,告诉应用程序,能接受push来的通知。
在项目的AppDelegate中添加下面的方法来获取deviceToken:
- - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- NSString *token = [NSString stringWithFormat:@"%@", deviceToken];
- NSLog(@"My token is:%@", token);
- }
- - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
- NSString *error_str = [NSString stringWithFormat: @"%@", error];
- NSLog(@"Failed to get token, error:%@", error_str);
- }
获取到的deviceToken,我们可以提交给后台应用程序,发送通知的后台应用程序除了需要知道deviceToken之外,还需要一个与APNS连接的证书。
这个证书可以通过我们前面生成的两个文件中得到。
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 -in Push.p12
3、创建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
如果后台应用是php的话,那么可以按照 iOS消息推送机制中pem文件的生成这篇文章中的方法来生成php后台应用程序中使用的证书文件:ck.pem
- iOS推送大全
- iOS推送 (百度推送)
- iOS推送 (百度推送)
- iOS- 推送极光推送
- iOS推送
- IOS推送
- ios推送。。。
- IOS推送
- ios 推送
- IOS 推送
- iOS推送
- IOS推送
- IOS推送
- IOS推送
- IOS推送
- iOS 推送
- ios推送
- iOS 推送
- libsvm 训练后的模型参数讲解
- centOS6.5 命令配置ip地址
- Tomcat集群配置学习篇-----分布式应用
- 在linux上搭建mycat环境
- Android中的Touch事件
- iOS推送大全
- 修改选择文件文本框及按钮样式
- Linux centos关机与重启命令详解
- android:popupwindow响应返回键消失但不退出当前activity
- CentOS6.5安装配置Samba
- web开发中的四个域对象生命周期 作用域详细介绍
- webSocket、Ajax轮询、长轮询(long poll)
- Array.prototype.slice.call(arguments)
- SVM中遇到的非均衡数据集