Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Messaging click_action format is platform specific?

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?

like image 979
Ralf Bokelberg Avatar asked Feb 17 '17 12:02

Ralf Bokelberg


People also ask

What are the two types of messages in Firebase Cloud Messaging?

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.

How does Firebase Cloud Messaging works?

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.

What protocol does FCM use?

FCM supports server protocols HTTP and XMPP which are identical to GCM protocols.

Is FCM token unique?

Yes, they are unique but they are not constant.


2 Answers

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.

like image 87
AL. Avatar answered Nov 15 '22 11:11

AL.


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.

like image 45
android_jain Avatar answered Nov 15 '22 10:11

android_jain