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

[Bug]: When the app is closed, notifications that were received while it was open do not open the app #977

Open
2 of 3 tasks
AlexFlorenco opened this issue Nov 29, 2024 · 3 comments

Comments

@AlexFlorenco
Copy link

What happened?

My problem only happens when I receive a notification with the app running (in the foreground or background). When you kill the app and click on the notification, nothing happens.
The notification just disappears.

I noticed that the same problem happens with the OneSignal example project here on github.
Is this a known limitation?

In all other situations, notifications work perfectly, in the foreground, background and dead.

Steps to reproduce?

class NotificationService {
  NotificationService._();
  static final NotificationService instance = NotificationService._();

  bool initialized = false;
  bool appInBackground = false;
  bool appOpenByNotification = false;

  Future<void> initialize() async {
    OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
    OneSignal.initialize("MY_APP_ID");
    OneSignal.LiveActivities.setupDefault();
    OneSignal.Notifications.clearAll();

    OneSignal.Notifications.addClickListener((event) {
      if (appInBackground) {
        appOpenByNotification = true;
        AdsService.loadAndShowNotificationAd(callback: () {
          handleNotificationReceived(event);
          appOpenByNotification = false;
        });
      } else if (initialized) {
        AdsService.loadAndShowNotificationAd(callback: () {
          handleNotificationReceived(event);
        });
      } else {
        appOpenByNotification = true;
        Timer.periodic(const Duration(milliseconds: 500), (timer) {
          if (initialized) {
            timer.cancel();
            handleNotificationReceived(event);
          }
        });
      }
    });

    OneSignal.Notifications.addForegroundWillDisplayListener((event) {
      event.preventDefault();
      event.notification.display();
    });
  }
}

What did you expect to happen?

I expected the closed app to start when clicking on the notification that was received when the app was running

OneSignal Flutter SDK version

5.2.8

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ErnestoMoraes
Copy link

Comigo acontece a mesma coisa... Fico no aguardo de alguma atualização!

@ivnaBat
Copy link

ivnaBat commented Nov 30, 2024

The same thing is happening to me as well. I noticed this issue about two days ago. I have a Flutter app integrated with OneSignal for long time, and I have never observed this behavior before.

However, in my case, the notification doesn't disappear. Instead, it moves to the end of the notification list. When I click it a second time, it works.

@AlexFlorenco
Copy link
Author

However, in my case, the notification doesn't disappear. Instead, it moves to the end of the notification list. When I click it a second time, it works.

It's true, I noticed that on some devices this also happens too

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

No branches or pull requests

3 participants