2017-08-30 97 views
1

我正嘗試使用郵遞員在我的iOS應用中創建和測試Apple通知。APNS提供商API和郵差

由於我沒有得到的原因,我從Postman發送到https://api.development.push.apple.com/3/device/<token-device>https://api.push.apple.com/3/device/<token-device>的請求失敗,未收到任何HTTP響應。

什麼我迄今所做的:

1 - 創建,從我的賬戶developer.apple.com導出的APNS憑證(如解釋there)。

2 - 轉換此的.p12證書與最近OpenSSL版本(1.0.2l)至爲.pem證書和密鑰這樣的:

openssl pkcs12 -in apns.p12 -out apns.crt.pem -clcerts -nokeys 
openssl pkcs12 -in apns.p12 -out apns.key.pem -nocerts -nodes 

3 - 配置郵差(首選項>證書)來使用這兩個提供商API網址(dev和prod)的.pem文件

4 - 爲我的設備令牌設置一個POST請求給我的設備令牌,其中apns-topic標題的值爲我的包ID,這個:

{ 
    "aps" : { 
     "alert" : { 
      "title" : "Game Request", 
      "body" : "Bob wants to play poker" 
     } 
    } 
} 

失敗,「無法獲得任何回覆,blablabla」。

如果我查個究竟吧郵差控制檯,我看到:

POST https://api.development.push.apple.com/3/device/12340e529f85a145b567736e7fd84c9d7e42a43a3c343ec378c2ff071011e4 06:18:08.236

Error: Parse Error

Client Certificate:

keyPath:"/Users/thomas/wksp_myproj/apns.key.pem"

pemPath:"/Users/thomas/wksp_myproj/apns.crt.pem"

Request Headers:

cache-control:"no-cache"

Postman-Token:"99615df2-b2aa-4a51-8d15-8ce27f4e8ca9"

Content-Type:"application/json"

apns-topic:"myproj.app"

此外,當我使用OpenSSL測試其解釋there

openssl s_client -connect api.development.push.apple.com:443 -cert apns.pem -debug -showcerts -CAfile GeoTrust_Global_CA.pem

我得到了很多的輸出與最後: HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: 0aread from 0x7f9445c215c0 [0x7f9446015c03] (5 bytes => 0 (0x0)) read:errno=0

怎麼回事?

+0

不知道這是爲什麼我得到這個錯誤,但似乎APS提供程序API需要Postman不支持的HTTP/2:(... –

回答

0

好吧,忘了郵差,我已經使用curl與http2和openssl(1.0.2l)的更新版本,它工作得很好。對於那些希望看到一個捲曲命令示例的人,這是here