iOS didNotificationLaunchAppreturn false and nullable payload when click on Notification in killed State
Describe the bug didNotificationLaunchApp returns false, and the payload is empty if the app was in a terminated state and the user clicked on the DarwinNotificationAction. Keep in mind that Android works as expected for similar steps. I encountered with issue only on iOS..
To Reproduce
- I receive Pushes using the library https://pub.dev/packages/firebase_messaging
- I added buttons to a category during app initialization. For example, the active_leak category has two buttons. Please take a look code below.
- Open the app at least once.
- Allow notifications for the app.
- Minimize the app and swipe it away (Terminate state – the app is not running in the background or in the list of active apps).
- Send a push notification via APNs, where the category matches the one from step 1: "category": "active_leak".
- Receive the push notification.
- Tap on one of the buttons.
- The app opens.
- getInitialMessage(https://pub.dev/packages/firebase_messaging) returns null and even final NotificationAppLaunchDetails? notificationAppLaunchDetails = await notificationsPlugin.getNotificationAppLaunchDetails().didNotificationLaunchApp returns false
Expected behavior didNotificationLaunchApp should return true, and the payload should not be empty if the app was opened using DarwinNotificationAction. Isn't that correct?
That is how I add the ActionButtons using the flutter_local_notifications library
DarwinNotificationAction actionIgnoreLeak = DarwinNotificationAction.plain(
NotificationButtonAction.ignoreLeak.value,
ignoreStr,
options: <DarwinNotificationActionOption>{
DarwinNotificationActionOption.foreground,
},
);
DarwinNotificationAction actionActiveLeak = DarwinNotificationAction.plain(
NotificationButtonAction.activeLeak.value,
detailsStr,
options: <DarwinNotificationActionOption>{
DarwinNotificationActionOption.foreground,
},
);
DarwinNotificationCategory categoryIgnoreAndDetails =
DarwinNotificationCategory(
NotificationBuilder.darwinNotificationCategoryActiveLeak,
actions: <DarwinNotificationAction>[
actionIgnoreLeak,
actionActiveLeak,
]);
initializationSettingsDarwin = DarwinInitializationSettings(
requestAlertPermission: false,
requestBadgePermission: false,
requestSoundPermission: false,
notificationCategories: <DarwinNotificationCategory>[
categoryIgnoreAndDetails
],
);
I am using the Postman to sent Pushes on my device. That is my JSON for Postman call. Feel free to check https://stackoverflow.com/a/62670409/21734721 how to grab Bearer token from Google for Postman. Sample code to send push via the Postman
{
"message": {
"token": "eztm3jfE9UsgrphZUCSSMe:APA91bFj8qulosQh-_4mGlBk-96eWRQ62_kesdSQ0ICGVSKM9ylKVZWBtzhbN5esGMS5cJK3d4epzUDnq_q1CC8HKp3vCUi-faJLIlE7S_5eK4u8HxlDcCs",
"notification": {
"title": "some text",
"body": "some text (optional)",
},
"data": {
"style": "red_high_leak",
"title": "some text (optional)",
"message": "some text",
"bodyAction": "active_leak",
"contextDataType": "leak",
},
"apns": {
"headers": {
"apns-priority": "5",
},
"payload": {
"aps": {
"category": "active_leak",
"content-available": 1,
"mutable-content" : 1,
}
}
},
},
}
same issue
Based on what you've mentioned, the notification being shown is a push notification via FCM. Is this correct? If so, then the issue would be on FCM side. The getNotificationAppLaunchDetails() method is only intended for local notifications
@MaikuB Thank you for your reply. I have already created a ticket in FCM repo to research it https://github.com/firebase/flutterfire/issues/17051
You can get notification details in terminated state using firebase messaging getInitialMessage() method