Open4

FCMのPush通知テスト

kzkyutakzkyuta

このやり方でアクセストークン取れた場合、Postmanからリクエスト送れる。
その時のコマンドは以下の通り

curl --location 'https://fcm.googleapis.com/v1/projects/fastdoctor-doctor-app/messages:send' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <アクセストークン>' \
--data '{
    "message":{
        "notification": {"title": "test", "body":"body"},
        "token": <FCMトークン>,
        "apns": {
            "headers": {
                "apns-priority": "10"
            },
            "payload": {
                "aps": {
                    "sound": "default"
                }
            }
        }
    }
}'

https://qiita.com/nishi-sankosc/items/b9040ee57e6b7223ff21

kzkyutakzkyuta

FCMからiOSにPushを送る場合、FCMにAPNs証明書かAPNsキーを登録しないといけない。
登録直後はUnauthorized Error → Internal Errorが出て送信できなかったが、登録してから12時間後再度やってみたらうまく行った。

ちなみにiOSエミュレータに向けてPushは飛ばせないので注意
https://qiita.com/flatwhite/items/0ec3883070d438872c7a

一方送信できるよとの記事も見つけてこれを試してみたがうまくいかなかった(気がする)
https://alimovshohrukh.medium.com/displaying-fcm-notifications-on-ios-simulators-4d2a90bc478e