I am using Firebase Cloud Messaging to send notifications to clients of my app. The clients can be any of the three supported platforms (ios, android, web).
I want the user to be able to click on the notification to launch the app.
For this i have to specify a click_action in the notification.
For ios and android that seems to be a simple string.
For web it would be an url.
How am i supposed to send a notification that works for a potentially mixed set of devices?
Do i have to separate the devices and send different messages to them?
Using Firebase Cloud Messaging, we can send three types of messages, i.e., Notification Message, Data Message, and the message with both Notification & Data Payload.
Aggregated delivery data via the FCM Data API. The Firebase Cloud Messaging Data API lets you retrieve information that can help you understand the outcomes of message requests targeted to Android applications. The API provides aggregated data across all data collection-enabled Android devices in a project.
FCM supports server protocols HTTP and XMPP which are identical to GCM protocols.
Yes, they are unique but they are not constant.
Update: A recent feature was added for FCM that gives an option to provide specific params for specific platforms, called Platform Overrides.
Each platform may handle the same notification differently depending on your payload.
The click_action
parameter is supported for all 3 platforms (Android, iOS, Web):
The action associated with a user click on the notification.
Each having different notes:
Android
If specified, an activity with a matching intent filter is launched when a user clicks on the notification.
iOS
Corresponds to category in the APNs payload.
Web
For all URL values, secure HTTPS is required.
The note for Web doesn't say that you can only have URLs as it's value, just that IF it is a URL, it should have secure HTTPS (for security reasons).
It is okay to send a single notification for all platforms, so long as you are able to handle them accordingly and to you're liking. However, as also advised in the other answer, it is better for you to send different payloads depending on the platform.
FCM works based on IDs generated by devices which are different depending on the device, platform, and curl session. So, they would be different for Android, iOS and Web. If you want to send to all platforms, you have to call the method three times (once for each platform) with a different payload or curl session for each. I'm sending to two platforms (iOS and Android) with two different function and calling them at the same time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With