IOS data notifications with FCM
<p>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. </p>

<p>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.</p>

<p>My question is that can I send a custom data notification message and make it appear instantly even when the app is closed. </p>

<p>This is the payload I am sending to FCM:</p>

<pre><code>{
    registeration_ids : [&lt;id_1&gt;, &lt;id_2&gt;],
    data : {
        title   : message_title,
        body    : message_body, 
        intended_user : message_user
    }
}
</code></pre>

<p>In android <code>FirebaseMessagingService.onMessageReceived()</code> is invoked even if the app is in the background but in ios <code>didReceiveRemoteNotification()</code> is only invoked when the application is launched so no background messages will appear if you send a data message.</p>