2016年6月1日 星期三

[技術] Parse Server的Android與iOS推播設定

參考資料:

https://parse.com/tutorials/push-notifications

https://github.com/ParsePlatform/Parse-Server/wiki/Push

https://github.com/ParsePlatform/Parse-Server/wiki/Push-Configuring-Clients

前面需要在Apple Developer跟Google Console要設定的東西就不詳細介紹,Apple需要憑證來建一個.p12檔來使用,Google Console需要設定一個伺服器端API金鑰、一個Android端金鑰、一個Android端的OAuth 2.0 用戶端 ID。

Server端設定:

push: {
    android: {
      senderId: '', // The Sender ID of GCM
      apiKey: '' // The Server API Key of GCM
    },
    ios: {
      pfx: '', // The filename of private key and certificate in PFX or PKCS12 format from disk  
      passphrase: '', // optional password to your p12
      cert: '', // If not using the .p12 format, the path to the certificate PEM to load from disk
      key: '', // If not using the .p12 format, the path to the private key PEM to load from disk
      bundleId: '', // The bundle identifier associate with your app
      production: false // Specifies which environment to connect to: Production (if true) or Sandbox
    }
  }

這邊官方寫的設定,我沒有設定senderId是可以送推播的,這邊註記一下。

其他在Android跟iOS端的設定,按照上面的參考資料來設定就可以了。

搞了兩天才搞好,真的很累人。

另外也在這邊紀錄一下,之前用php實作推播的時候,在Server也沒有用到senderId,另外也有搜尋到也有人說在Parse上也不用設定senderId,所以才試成功的...。

另外,在第一次是成功的時候,是先把整個GCM跟Parse的Android設定全部寫在一起,這時候Parse上抓到的deviceToken出現了這樣的格式:
|ID|1|:{deviceToken}
但是在Parse上存這樣的資料,Parse Push是沒有辦法正常運作的。所以後來把整個GCM端的設定都拿掉,也是可以運作的。