概要
FCMではtopic
宛にメッセージを送ることで、topic
に登録した端末に一斉にpush通知を送ることができます。topic
に端末を登録する際、端末のfcm registration token
(以下TOKEN
)を使用しますが、これはアプリを再インストールした場合等に更新されます。TOKEN
が更新された場合topic上でどう扱われるか気になったので、試してみました。
結論
TOKENが更新された場合、更新前に登録していたtopicからは通知が来なくなることがわかりました。ですが、topic
い登録していた古いトークはどうなるんでしょうね?古いトークンを使って明示的にunsbscribeすることはできないようなのですが、更新されたら勝手にunsbscribeにしてくれているんですかね。。
実験
topicへ端末を登録
$ curl -XPOST --header "Authorization: key=${SERVER_KEY}" \
--header "Content-type: application/json" \
--header "Content-Length: 0" \
"https://iid.googleapis.com/iid/v1/${TOKEN}/rel/topics/test"
登録状況の確認
$ curl --header "Authorization: key=${SERVER_KEY}" \
"https://iid.googleapis.com/iid/info/${TOKEN}?details=true" | jq
{
"applicationVersion": "1",
"connectDate": "2018-07-12",
"attestStatus": "NOT_ROOTED",
"application": "com.example",
"scope": "*",
"authorizedEntity": "111111111111",
"rel": {
"topics": {
"test": {
"addDate": "2018-07-12"
}
}
},
"appSigner": "xxxxxxx",
"platform": "ANDROID"
}
メッセージの送信
$ curl --header "Authorization: key=${SERVER_KEY}" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{
\"to\" : \"/topics/test\",
\"data\" : {
\"message\": \"hello\"
}
}"
受信できました。
アンインストール&再インストール&登録状況の確認
$ curl --header "Authorization: key=${SERVER_KEY}" \
"https://iid.googleapis.com/iid/info/${TOKEN}?details=true" | jq
{
"error": "No information found about this instance id."
}
$ curl --header "Authorization: key=${SERVER_KEY}" \
"https://iid.googleapis.com/iid/info/${NEW_TOKEN}?details=true" | jq
{
"applicationVersion": "1",
"connectDate": "2018-07-12",
"attestStatus": "NOT_ROOTED",
"application": "harutacompany.sample.message",
"scope": "*",
"authorizedEntity": "366365399328",
"appSigner": "c40ce9d10d3d1ac89519090ae031de3f1f50af42",
"platform": "ANDROID"
}
メッセージの送信
$ curl --header "Authorization: key=${SERVER_KEY}" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{
\"to\" : \"/topics/test\",
\"data\" : {
\"message\": \"hello\"
}
}"
受信できませんでした。