Flutter - Firebase Cloud Messaging, Data Message is not received on iOS
IOS messages come with a different structure, you don't need 'data' for IOS an example could be
if(Platform.isAndroid){ roomId = message['data']['chatRoomId']; senderId = message['data']['senderId']; }else if(Platform.isIOS){//without data roomId = message['chatRoomId']; senderId = message['senderId']; }
On iOS, the data is directly appended to the message and the additional data-field is omitted.To receive the data on both platforms, your myBackgroundMessageHandler() function should look like this:
Future<void> myBackgroundMessageHandler(Map<dynamic, dynamic> message) async { var data = message['data'] ?? message; print(data); String expectedAttribute = data['expectedAttribute']; }
You can learn more about this on the Firebase Messaging Flutter documentation, under the "Notification messages with additional data" section.