I cannot receive data-only Firebase messages on my Flutter iOS client when my application is in the foreground. I have been experimenting with this for days without success.
Data+notification messages do work (when my app is in the foreground) and are successfully received by my FirebaseMessaging.onMessage.listen event handler. On Android, everything works as expected.
Flutter configuration:
firebase_core: ^2.10.0firebase_messaging: ^14.4.1
I am sending Firebase data-only messages from a PHP page using firebase-php 6.9.5 using the following code:
$message = CloudMessage::withTarget(MessageTarget::TOKEN, $registrationToken);
$message = $message->withData($data);
I have also tried to add:
$message = $message->withApnsConfig(['headers' => [
'apns-priority' => '5',
"apns-topic" => 'io.flutter.plugins.firebase.messaging'
]);
as setting an apns-priority of exactly the value of 5 seems to be the way to go for data-only messages. Not sure about apns-topic but included anyway.
But this does not work either.
Please note that firebase-php version 6.9.5 automatically adds the content-available key with a value of 1 to the payload and apns-push-type (value: 'background') to the headers when sending data-only messages for iOS, as mentionned here:
https://github.com/kreait/firebase-php/issues/700
I traced the PHP code and verified this is indeed the case.
No matter what I do, I cannot get a data-only message received on the Flutter iOS client side.