I want to send two different notifications to Android and iOS. I want to send a notification message to iOS, this way iOS displays a nice notification. For Android I want to send a data message, this way I can handle the notification on Android and also in the background (because I don't get a callback in the background and want to handle it myself).
I looked through the docs, but couldn't find anything about sending to a specific platform. How do I do that?
Also other suggestions on how to do this are welcome, but keep in mind that I specifically want to handle the notification myself through a callback on Android (onMessageReceived)
I was facing same issue with Android Development. We used Laravel on backend side. On backend side, developer has to maintain different scenario for both platforms.
In Android :
Here, null is passed as a notification builder. When you pass null in notification and create databuilder($data), you can receive message in onMessageReceived method when app in background.
For iOS :
Here, you can pass notification builder in $notification. So, iOS device can also get notification.
Update: A recent feature was added for FCM that gives an option to provide specific params for specific platforms, called Platform Overrides:
I remember answering a similar question before but cant seem to find it. There is currently no option to specify which platform a message would be sent. The simplest way you could do this is by using Topics Messaging.
Everytime the token is generated for the first time, you determine from your client app the Platform type and subscribe them to the corresponding topic (e.g.
topics/(Android/iOS)_<Your App Name>
), then sned the messages as needed.It's also good to keep track of the registration tokens from your Server, if you're using Firebase DB, you could put them inside a node:
This would let you check from your backend side and adjust your payload as needed when sending single messages.