5

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?

Ralf Bokelberg
  • 405
  • 5
  • 9

2 Answers2

8

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.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • In your comment on a [related question](https://stackoverflow.com/q/48457799/4815718), you indicate that `click_action` is not supported. Is that comment obsolete? – Bob Snyder Mar 08 '18 at 16:45
  • Ignore my previous comment. I see now this answer is for the legacy FCM. I was confused by the link to _Platform Overrides_, which describes the FCM v1 HTTP protocol options. – Bob Snyder Mar 08 '18 at 16:51
  • 1
    `click_action` is not supported for web in HTTP V1. I spent a long time trying to figure it out. It's simply not supported. – Nick Mar 14 '18 at 10:09
3

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.

Donut
  • 110,061
  • 20
  • 134
  • 146
android_jain
  • 788
  • 8
  • 19
  • Note that this approach makes it hard to use Device Groups and Topics in FCM. You would have to create platform-specific groups and topics. – nicoqh Oct 25 '17 at 15:14