I am sending the following payload to FCM API
{
message: {
token: DEVICE_TOKEN,
apns: {
headers: {
'apns-priority': '5',
'apns-push-type': 'alert',
'apns-collapse-id': '113',
},
payload: {
aps: {
alert: {
title: 'Brand new title',
body: 'Brand new text',
},
category: 'XYZ_CATEGORY',
},
},
},
},
}
I have written the following background remote notification handler outside of any class as a top-level function in my Flutter app:
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage rMessage) async {
await Firebase.initializeApp();
debugPrint('Handling a background message ${rMessage.toMap()}');
}
Here's the output in the console where the collapseKey
is null.
{
senderId: null,
category: 'XYZ_CATEGORY',
collapseKey: null,
contentAvailable: true,
data: {},
from: null,
messageId: 1706272050712326,
messageType: null,
mutableContent: false,
notification: {
title: 'Brand new title',
titleLocArgs: [],
titleLocKey: null,
body: 'Brand new text',
bodyLocArgs: [],
bodyLocKey: null,
android: null,
apple: {
badge: null,
subtitle: null,
subtitleLocArgs: [],
subtitleLocKey: null,
imageUrl: null,
sound: null,
},
web: null,
},
sentTime: null,
threadId: null,
ttl: null,
}
The apns-collapse-id
is not mapped to the collapseKey
.
My questions:
The collapseKey
is only valid in case of Android. The apns-collapse-id
doesn't map to this property in Firebase.
As per my observation, replacing a notification doesn't have to be done manually. If you send a remote notification with apns-collapse-id
as 1
, then send the following remote notification with the same id, the iOS handles replacing the older notification with the newer one.