LoginSignup
6
5

More than 5 years have passed since last update.

Apple PushのトークンをFirebase Cloud Messagingのトークンへ変換する

Posted at

Firebase Cloud Messaging は iOS と Android の両方に、単一のAPIでプッシュ通知を送信できます。

各OS への SDK 組み込み:
https://firebase.google.com/docs/cloud-messaging/ios/client
https://firebase.google.com/docs/cloud-messaging/android/client

サーバからプッシュ通知を送信する API:
https://firebase.google.com/docs/cloud-messaging/downstream

もちろん、各OSでプッシュ通知の機能が少し違うので、それぞれに向けたパラメータも用意されています:
https://firebase.google.com/docs/cloud-messaging/http-server-ref#header

Go で Firebase Cloud Messaging でプッシュ通知を送信するクライアントも作ってみました github.com/najeira/fcm

iOSの従来トークンからの変換

さて、Firebase の SDK を組み込むことでアプリから Firebase Cloud Messaging のトークンを取得できますが、いままで取得した APNs のトークンを活用したい場合は以下の API で変換できます。

これは Google Cloud Messaging の API ですが、Firebase Cloud Messaging と統合されたので、この API で得られたトークンをそのまま使うことができます。Authorization ヘッダーに入れる API Key も Firebase のもので OK です。

Go 用の変換処理は github.com/najeira/convert_apns_to_fcm こちらに書いてみました。

見ればわかりますが、単純な JSON API なので、他の言語で実装するのも簡単だと思います。


いままで iOS と Android で別に管理していた処理をひとつの API に統合できるので、実装も運用もシンプルになりますね!

6
5
0

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
5