首頁 > 軟體

iOS推播功能實現步驟

2019-12-05 00:07:40

1. app端推播證書等組態檔的建立;

2. php推播伺服器ssl證書的建立;

1

在developer.apple.com的member center設定AppId屬性,

enable push.



2

在developer.apple.com的member center建立APN證書,

Development -> Apple Push Notification service SSL (Sandbox) 用於沙盒app

Production -> Apple Push Notification service SSL 用於AppStore app

建立完畢後,可以第一步AppId的屬性列表中檢視到證書名稱




3

基於第1步修改的AppID重新生成provision file,

在iOS Project中載入此provision file,

這樣編譯出的app才可以獲取到device token(推播唯一識別符號)




4

以下為針對伺服器端的推播設定步驟--------

在keychain中找到第1步建立的APN證書,

展開此證書,分別匯出證書和金鑰,

名稱設為cer.p12和key.p12


5

開啟控制台程式,使用openssl 將cer.p12及key.p12轉成cer.pem和key.pem命令如下:$ openssl pkcs12 -clcerts -nokeys -out cer.pem -in cer.p12$ openssl pkcs12 -nocerts -out key.pem -in key.p12

6

測試生成的cer.pem及key.pem是否可用$ openssl s_client -connect gateway.push.apple.com:2195? -cert cer.pem -key key.pem?註:gateway.push.apple.com:2195用於appStore app;? ? ? ?gateway.sandbox.push.apple.com:2195用於沙盒app;? ? ? ?以上命令執行後會列印一大羅資訊,最後處於可輸入狀態,打幾個字元回車後自動斷開連線即為正常。

7

合併cer.pem及key.pem$ cat cer.pem key.pem > ck.pem

8

上傳ck.pem到推播伺服器的推播程式的目錄。Tip:-----------------------find / -name "*.php" ? ? ? ?查詢推播伺服器php檔案目錄用。scp ~/Desktop/ck.pem root@xx.xx.xx.xx:/var/www/html ? ?用於上傳本地檔案到Linux伺服器用。

9

伺服器php程式碼載入ck.pem向蘋果伺服器推播訊息:略用戶端oc程式碼獲取token,接收推播訊息:略

IT145.com E-mail:sddin#qq.com