LoginSignup
6

More than 5 years have passed since last update.

GaurunでのGCM(FCM)とAPNsの設定方法

Posted at

GaurunのGCMとAPNsの設定に苦戦したのでメモ。

【動作環境】
Ubuntu14.04
Gaurun 0.8.1

GCM(FCM)のAPI Keyを発行する

FirebaseからAPIキーを発行する。
https://firebase.google.com/docs/cloud-messaging/server?hl=ja#http--

上記ページにも記載されているが、
APIキーが正しいものかを確認するには下記コマンドを実行する。
401エラーが出なければOK。

api_key=YOUR_SERVER_KEY

curl --header "Authorization: key=$api_key" \
       --header Content-Type:"application/json" \
       https://fcm.googleapis.com/fcm/send \
       -d "{\"registration_ids\":[\"ABC\"]}"

APNsの証明書と鍵を発行する

APNs Provider APIを使用する。
https://developer.apple.com/jp/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html#//apple_ref/doc/uid/TP40008194-CH101-SW1

証明書と鍵の発行は下記サイトを確認する
https://developer.apple.com/jp/documentation/IDEs/Conceptual/AppDistributionGuide/AddingCapabilities/AddingCapabilities.html#//apple_ref/doc/uid/TP40012582-CH26-SW11

p12ファイルを入手したら下記コマンドを実行し、証明書と鍵ファイルを生成する。

openssl pkcs12 -clcerts -nokeys -out hoge_cert.pem -in hoge.p12
openssl pkcs12 -nocerts -out hoge_key.pem -in hoge.p12

この証明書が正しいかどうかは下記コマンドで確認できる。
エラーが出なければOK。

# 開発環境
sudo openssl s_client -connect api.development.push.apple.com:443 -cert hoge_cert.pem -key hoge_key.pem

# 実稼働環境
sudo openssl s_client -connect api.push.apple.com:443 -cert hoge_cert.pem -key hoge_key.pem

Gaurunの設定

gaurun.tomlに設定する内容を記載する。
GCMおよびAPNsに関するもののみ抜粋。

[android]
enabled = true
apikey = "上記で生成したGCM(FCM)のキー"
use_fcm = true # 今回はFCMを使用したのでtrue

[ios]
enabled = true
pem_cert_path = "上記で生成したcertファイルのパス"
pem_key_path = "上記で生成したkeyファイルのパス"
sandbox = true # 開発環境用の証明書の場合、true
topic = "バンドルID"

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6