Posílání Push notifikací přes FCM
Posílání Push notifikací
Posilani push notifikaci (PN) přes Firebase Cloud Messaging (FCM) lze simulovat pomocí příkazu CURL. K tomu budeme potrebovat:
- Server key - který najdeme ve firebase consoli projektu (viz obrázek)
- Registration id - neboli token zařízení, který obdržíme v aplikaci během registrace push notifikaci (příklad získání tokenu)

Když si zjistíme tyto údaje, můžeme vyplnit curl příkaz (viz link):
Android
curl -i -H 'Content-type: application/json' -H 'Authorization: key=<server-key>' -XPOST https://fcm.googleapis.com/fcm/send -d '{
"registration_ids":["registration_ids", "of the", "target", "devices as array"],
"data": {
"title":"Title of your notification",
"body":"content of your notification",
"count":"5",
"image":"https://cdn.iconscout.com/icon/premium/png-256-thumb/darth-vader-8-627661.png",
"key1" : "key1",
"key2" : "value2",
"key3" : 23.56565,
"key4" : true
}
}'
iOS
curl -i -H 'Content-type: application/json' -H 'Authorization: key=<server-key>' -XPOST https://fcm.googleapis.com/fcm/send -d '{
"registration_ids":["registration_ids", "of the", "target", "devices as array"],
"notification": {
"title": "My Title",
"body": "My message"
}
"data": {
"key1": "data 1",
"key2": "data 2"
}
}'
PN můžeme posilat na vice zařízeni, stači vypsat tokeny do pole registration_ids.
Reference
https://gist.github.com/drulabs/c9f6802790c92d74cb7eb2427097899a
https://android.jlelse.eu/firebase-push-notification-using-curl-command-devoid-backend-e63795d282c4
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/EXAMPLES.md