Send silent push notification from Firebase consol

2020-02-26 09:41发布

问题:

Trying to prove a concept I've been working on for a while, which involves my app recieving a silent notification. I am using Firebase Cloud Messaging as it has less overhead than native APNs for the developer.

I know FCM supports silent notifications when you build the payload yourself on your own backend, which is of course my intention. However, I want to make sure I can do what I want to do with this notification, and therefore want to prove it using the FCM console before I spend time writing my backend.

I have managed to send standard notifications from here, but not silent ones. Even when I include the content-available flag I'm still alerted. I think this is due to FCM always including the alert parameter in the JSON. Is there a way to disable this in the test console?

Many Thanks,

回答1:

There is no way to send notifications different from the standard kind from the Firebase Console.

A quite convenient way is to use Postman or curl with a set Authorization Header.

curl -H "Content-type: application/json" -H "Authorization:key=<YOUR-API-KEY>"  -X POST -d '{ "data": { "foo": "1","bar": "2"},"to" : "<YOUR-DEVICE-TOKEN>"}' https://fcm.googleapis.com/fcm/send


回答2:

You actually CAN send silent notifications from FCN. Check here.

Note: On iOS, set content_available when the app server needs to send a send-to-sync message. An inactive client app executes your logic in the background, while an app in the foreground passes the message to didReceiveRemoteNotification:.

Notice that the key you have to use is content_available, with underscore; different from content-available which is with a hyphen.