Glasset
Glasset

Reputation: 186

Set different sound notification

I have a pool of device tokens (iOS and Android) and in the docs, I find only one parameter sound for both platforms and obviously I have 2 different notification sound, one for Android and one for iOS.

Do I have to split device tokens by device type for sending to 2 separate device types? Or did I just miss something ?

Thanks.

Upvotes: 4

Views: 3325

Answers (2)

Isaac Bosca
Isaac Bosca

Reputation: 1648

Solution 1

You could name the same both audio files, like 'your_app.mp3'.

Same name, but different music file on each app. This not allow the user choose the notification sound, but at least allow each app to have a different sound.

Solution 2

Migrate to the new Firebase HTTP v1 API which allows you to customize notifications across platforms

Personal experience

Solution proposed by @daniel-raouf to send Data Messages is great; but in my experience, some Data Messages could not be delivered to your users when:

  1. An user has a power save mode on his phone (by default on Huawei, Xiaomi, One Plus...)

  2. When iOS users clear your app from recent apps (multitask).

So, in my opinion, Data Messages are not a reliable solution for notifications.

Upvotes: 1

Daniel Tadros
Daniel Tadros

Reputation: 2357

You had missed something,

A- If you want to allow the user to select his preferred notification sound at any device so

  1. don't send notification
  2. send only data to force the received content to pass by the onReceive event
  3. In on receive add the sound the icon and data you want to the notification builder.

B- If you want the app to use the default sound

so in the notification body set sound:'default' and it would work for all types of devices

Upvotes: 1

Related Questions