flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

iOS didNotificationLaunchAppreturn false and nullable payload when click on Notification in killed State

Open VictorJava opened this issue 10 months ago • 4 comments

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

  1. I receive Pushes using the library https://pub.dev/packages/firebase_messaging
  2. I added buttons to a category during app initialization. For example, the active_leak category has two buttons. Please take a look code below.
  3. Open the app at least once.
  4. Allow notifications for the app.
  5. Minimize the app and swipe it away (Terminate state – the app is not running in the background or in the list of active apps).
  6. Send a push notification via APNs, where the category matches the one from step 1: "category": "active_leak".
  7. Receive the push notification.
  8. Tap on one of the buttons.
  9. The app opens.
  10. 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,
         }
       }
     },
  },
}

VictorJava avatar Feb 05 '25 08:02 VictorJava

same issue

amit-iconflux avatar Feb 12 '25 12:02 amit-iconflux

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 avatar Feb 12 '25 12:02 MaikuB

@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

VictorJava avatar Feb 13 '25 07:02 VictorJava

You can get notification details in terminated state using firebase messaging getInitialMessage() method

Abdurahmon727 avatar Jun 23 '25 11:06 Abdurahmon727