您的位置:首页 > 移动开发 > IOS开发

iOS消息推送整体流程

2014-04-17 10:42 316 查看
具体实现

一、获取推送服务认证书

该认证书 是用于服务器与APNS服务器SSL 连接时的认证,而获取p12的前提是获取APNS Assistant。

1. 在apple开发中心生成 App ID(如PushDemo),注意:Bundle Indentifier值格式必须为反向域名格式,如com.bluestar.PushDemo;

2. 单击App ID 的后面的 Configure;

3. 在新的页面中,勾选Enable Push Notification Services , 而后点击Configure ,随后出现APNs Assistant,APNs助手会引导生成你的程序与APNs服务器进行SSL连接的认证书App ID specific Client SSL certificate[注释:一般文件名为“aps_developer_identity.cer” 可修改]

4. APNs助手会引导你保存SSL certificate到你的硬盘,保存好后双击,安装到你的keychain;

5. 执行完以上四步,可以点击Done,关闭APNs助手;

6. 启动Keychain Access程序,查看刚才安装的认证,name 为apple Development/Production push Services。。。

导出--即获得Certificates.p12 保存好给Provider 服务器使用;

二、IOS应用程序开启推送服务

1. iPhone provisioning 以开启了PUSH功能App ID (如前述PushDemo)生成相应的provisioning,并下载;

2. 以前述App ID(PushDemo),创建应用程序,并指定Bundle Indentifier为注册时使用的Bundle Indentifier (本例为com.bluestar.PushDemo);

3. iPhone需要用到的方法函数如下:

//注册启用 push

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge /*|UIRemoteNotificationTypeSound*/)];

//用该判断 程序是不是通过push消息启动的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

//iPhone 从APNs服务器获取deviceToken后激活该方法

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

//注册push功能失败 后 返回错误信息,执行相应的处理

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err

附录:使用OpenSSL转换证书格式

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. 将Certificates.p12格式的私钥转换成pem,需要设置4次密码,密码都设置为:abc123。

openssl pkcs12 -nocerts -out aps_developer_key.pem -in Certificates.p12

3. 用certificate和the key 创建PKCS#12格式的文件。

openssl pkcs12 -export -in aps_developer_identity.pem -inkey aps_developer_key.pem -certfile PushTest.certSigningRequest -name "aps_developer_identity" -out aps_developer_identity.p12
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: