I am using FCM (firebase cloud messaging) to send "custom" data notifications to an IOS app. From what I understand, we use notification messages when you want FCM to handle displaying a notification on your app's behalf. And we use data messages when you just want to process the messages only in your app. It's by design.
Problem I am facing is that that Device/InstandID token is unique to installed app and not the user logged in the app. So to solve this, I am sending intended user tag in the data so it becomes a data message. Since the app handles the data notifications, the didReceiveRemoteNotification() callback is only fired when the app is opened and the notification is only shown than and not instantly when it's sent.
My question is that can I send a custom data notification message and make it appear instantly even when the app is closed.
This is the payload I am sending to FCM:
{
registeration_ids : [<id_1>, <id_2>],
data : {
title : message_title,
body : message_body,
intended_user : message_user
}
}
In android FirebaseMessagingService.onMessageReceived()
is invoked even if the app is in the background but in ios didReceiveRemoteNotification()
is only invoked when the application is launched so no background messages will appear if you send a data message.