Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getNotificationAppLaunchDetails on iOS returning false without payload #512

Closed
d3xt3r2909 opened this issue Mar 2, 2020 · 7 comments · Fixed by #515
Closed

getNotificationAppLaunchDetails on iOS returning false without payload #512

d3xt3r2909 opened this issue Mar 2, 2020 · 7 comments · Fixed by #515

Comments

@d3xt3r2909
Copy link

Hi @MaikuB, thank you for the great library.

I have an issue where getNotificationAppLaunchDetails is returning me always false and payload null as a result on the iOS platform, while on Android these values are good, as should be.

To Reproduce
If applicable, steps to reproduce the behavior:

  1. Downloaded your example project
  2. Added part of code to function onSelectNotification callback (like on image in the attachment), just to access and print payload and got the result with false & null
  3. When you do the same thing on the android platform, you will have payload and true as value for didNotificationLaunchApp

image

Goal: I would love to be the same results on both platforms if it is possible.

@MaikuB
Copy link
Owner

MaikuB commented Mar 2, 2020

Sorry but the steps you described aren't sufficient to show how to reproduce the problem. I'm using the example app and don't see the issue you've described. didNotificationLaunchApp only returns true if the app was killed and you tapped on a notification (that was created by the app) to launch the app. None of your steps actually describe what you did with the notification.

@d3xt3r2909
Copy link
Author

Hi @MaikuB, sorry if my first post is not clear enough for you.

Can you please open your example project and replace code from line 61 to 67 :

await flutterLocalNotificationsPlugin.initialize(initializationSettings,
      onSelectNotification: (String payload) async {
    if (payload != null) {
      debugPrint('notification payload: ' + payload);
    }
    selectNotificationSubject.add(payload);
  });

with this code:

await flutterLocalNotificationsPlugin.initialize(initializationSettings,
      onSelectNotification: (String payload) async {
    if (payload != null) {
      debugPrint('notification payload: ' + payload);
    }

    final NotificationAppLaunchDetails details =
        await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();

    print("test me !-> ${details.payload}");

    selectNotificationSubject.add(payload);
  });

Then,

  1. Click on the first button "Show plain notification with payload"
  2. Tap on the notification that has shown up
  3. Of course onSelectNotification will be triggered

Now, on the Android side result of line print("test me !-> ${details.payload}"); will be "item x", while on same scenario, on iOS platform, this line of code will print null.

didNotificationLaunchApp only returns true if the app was killed and you tapped on a notification (that was created by the app) to launch the app.

This basically, resolves my question, because I was using another way for handling tap on the notification, and fetching data of click, based on getNotificationAppLaunchDetails();. Now, the only question is, why the behavior for this function is different for Android and iOS?

Also, is it possible to make a function that will return your payload of last shown notification (notification that is on the stack, and that user didn't already click on it?)

It would be very nice if you can add also an example of the usage of getNotificationAppLaunchDetails to your example project.

@MaikuB
Copy link
Owner

MaikuB commented Mar 5, 2020

Thanks for the info. Was able to reproduce but will need to see if it's possible to fix. The behaviour is different because the mechanisms on each platform are different.

Regarding getting notifications that are in still in the notifications centre/drawer (i.e. the active notifications), It's not possible via this plugin but there are native APIs that can get those notifications. They aren't supported by the plugin as these APIs can't be used by all supported versions of Android and iOS. They're only available for Android 6.0+ and iOS 10+. If your app will only be supporting those at a minimum then you'll need to write your own code to use those APIs within your app.

@d3xt3r2909
Copy link
Author

Regarding getting notifications that are in still in the notifications centre/drawer (i.e. the active notifications), It's not possible via this plugin but there are native APIs that can get those notifications. They're supported by the plugin as these APIs can't be used by all supported versions of Android and iOS. They're only available for Android 6.0+ and iOS 10+. If your app will only be supporting those at a minimum then you'll need to write your own code to use those APIs within your app.

Ok, understand. I will use the listener, or help of dartrx to listen events of opening notification on some other place in my code.

Thanks for the info. Was able to reproduce but will need to see if it's possible to fix. The behaviour is different because the mechanisms on each platform are different.

Yep, it would be cool, or at least, you can document this somewhere in readme.

Thanks for quick response,

All the best

@MadhanHoggy
Copy link

MadhanHoggy commented Jul 12, 2022

Getting the same issue in Android version :(
I have upgraded the flutter_local_notification package to 9.7.0 , but still details.payload displays null

    final NotificationAppLaunchDetails details =
        await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();

    print("test me !-> ${details.payload}");

@nickcuypers
Copy link

@MadhanHoggy try this:

final NotificationAppLaunchDetails details =
        await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();

    print("test me !-> ${details.notificationResponse.payload}");

@tal412
Copy link

tal412 commented Nov 29, 2022

Having this issue on the latest iOS version.
No matter where I put it, didNotificationLaunchApp is always false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants