置頂文章

顯示具有 GCM 標籤的文章。 顯示所有文章
顯示具有 GCM 標籤的文章。 顯示所有文章

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端的設定都拿掉,也是可以運作的。

2015年12月15日 星期二

[Android] - Android 6.0以後的權限設定與GCM

因應Android 6.0以後對於手機權限的管理方式(如存取相機、位置、聯絡人、手機、儲存、日曆權限等等),在舊版的開發方式上會導致crash。
必須增加版本判斷來對權限有不同的寫法

權限的簡介
http://developer.android.com/intl/zh-tw/training/permissions/index.html

即時要求權限的範例:
http://developer.android.com/intl/zh-tw/training/permissions/requesting.html

權限列表資訊
http://developer.android.com/intl/zh-tw/guide/topics/security/permissions.html#permission-groups


GCM:
按照之前舊版的方式取得DeviceId在6.0的手機上會crash
所以去爬了一下官方文件
範例參考:
https://developers.google.com/instance-id/guides/android-implementation