iOS消息推送整体流程
生活随笔
收集整理的這篇文章主要介紹了
iOS消息推送整体流程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
具體實現
一、獲取推送服務認證書
該認證書 是用于服務器與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
總結
以上是生活随笔為你收集整理的iOS消息推送整体流程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 快充耐用还是慢充耐用
- 下一篇: iOS 证书相关概念