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

setNotificationOpenedHandler does not executes when app is terminated/not opened at all #540

Closed
apoorvpandey0 opened this issue Mar 5, 2022 · 30 comments

Comments

@apoorvpandey0
Copy link

apoorvpandey0 commented Mar 5, 2022

setNotificationOpenedHandler works very well when app is in background or in focus, but when app is swiped away i.e terminated by the user, This listener is not being called so I'm not able to access notification additional data.
I'm testing this with Flutter 2.10.1 and Onesginal SDK 3.2.8
I hope I'm clear, please help!

@andikanugraha
Copy link

yes, I'm also having this issue. Is there any solution for this?

@mjarpitanand
Copy link

Same error i am getting.

@ayechan-maung
Copy link

We all get errors like that.

@mjarpitanand
Copy link

Any solution for this

@AmmarHazem
Copy link

Same issue here, any update on this ?

@nan-li
Copy link
Contributor

nan-li commented Apr 12, 2022

Hi all,

Thank you for reporting this issue.

Can you share the device information for this? Is it on Android and/or iOS? Type of phone, for example Huawei, etc.

@AmmarHazem
Copy link

AmmarHazem commented Apr 13, 2022

Thanks for replay @nan-li. I got this issue on iOS iPhone XR.

@apoorvpandey0
Copy link
Author

apoorvpandey0 commented Apr 13, 2022

Hi all,

Thank you for reporting this issue.

Can you share the device information for this? Is it on Android and/or iOS?

For me it was on Android, although I don't think this is a device specific issue and believe that this feature has not even been implemented in the SDK for flutter.
I also saw a PR where @efraespada has implemented this feature #464

@marcorubagotti
Copy link

Any updates?

@emawby
Copy link
Contributor

emawby commented Jun 24, 2022

@marcorubagotti We are still investigating the issue and working on a fix. I apologize for the delay and thank you for your patience

@mrqaidi
Copy link

mrqaidi commented Jun 26, 2022

Any updates?

@piotruela
Copy link

Any updates on this?

@daveshirman
Copy link

daveshirman commented Jul 22, 2022

To workaround:

  1. You need to store the result of the notification when your app loads e.g. in local storage, inside this method: setNotificationOpenedHandler.

  2. Then at some point after, check your storage for any notification data that came in.

After the app is loaded, the handler will run as expected.

@alexobviously
Copy link

alexobviously commented Jul 30, 2022

I also have this issue and the workaround above does not work, as the notification handler (passed to setNotificationOpenedHandler) is never called if the app is opened from a notification.

Device: Poco X3 NFC, Android 11 (MIUI 12.5.8)

Did this ever work? Is this a bug or just missing functionality?

@daveshirman
Copy link

daveshirman commented Jul 30, 2022 via email

@daveshirman
Copy link

daveshirman commented Jul 30, 2022 via email

@alexobviously
Copy link

alexobviously commented Jul 30, 2022

Yeah I have all the onesignal initialisation stuff before MaterialApp, even before WidgetsFlutterBinding.ensureInitialized();, and OneSignal.shared.setAppId is awaited. I've tried moving things around, adding delays in, etc, but it seems like nothing works. To confirm that the handler is never called, I put an exception in it, and it never occurs. The handler works as expected in all other cases - it's just when the app is opened from a notification that it doesn't.

Nothing like AdBlock running (though that is an interesting idea).

@daveshirman if you do have code you could share it would be very much appreciated (no rush!), maybe I've missed something.

@daveshirman
Copy link

daveshirman commented Aug 4, 2022

@alexobviously To keep this ticket cleaner, I moved my workaround over to my site, in case you still wanted it:

https://www.codingandclimbing.co.uk/blog/flutter-onesignal-additionaldata-on-app-start

@marcorubagotti
Copy link

@daveshirman i have follow your workaround as explained in your site. Like @alexobviously the handler works in all cases except when the app is closed.
May can depend on how I have configured the routes and home settings in MaterialApp() ?

@daveshirman
Copy link

daveshirman commented Sep 5, 2022 via email

@alexobviously
Copy link

Thanks for your code by the way @daveshirman. I tried exactly your example with my own onesignal config and it didn't work. So that confirms that there's some very mysterious, potentially device-specific bug (although we have tested on a fairly wide range of devices and none of them worked).
The only other possibility is that we have miscommunicated at some point so I'll just clarify for anyone who comes after this (hopefully someone from onesignal):
The issue is that when apps are cold booted from a notification, i.e. they are opened from a completely closed state by tapping a onesignal notification, the handler is not called when the app opens.

@daveshirman
Copy link

daveshirman commented Sep 5, 2022 via email

@marcorubagotti
Copy link

@daveshirman i have reviewed your workaround and the logic work but on app closed, when i tap the notification the context or navigationKey.currentState return null when try to navigate on a simple page.

I have implemented the navigationKey and onGenerateRoute logic but not work

@daveshirman
Copy link

Just for anyone who thinks my workaround doesn't work at all, here's a video of it literally working. This behaviour is identical on Android and this is a production app from TestFlight.

What's happening:

  1. First I'm swiping up, showing you that there's no app in the recent apps list.
  2. I tap the notification.
  3. App loads
  4. Saves a key-value store for that particular page from a payload data value in the OneSignal data
  5. App checks that value and loads the appropriate page onto the stack - "Latest Content"

https://imgur.com/a/VE28Iur

@glin94
Copy link

glin94 commented Sep 23, 2022

I noticed this problem on Xiaomi Note 10s (Android 11 MIUI 12.5.9), but on another device Xiaomi Note Pro 8 (Android 10 MIUI 12.0.5) everything works fine. I also checked on emulator (Android 11 ) and everything works

@Oliver-Knight
Copy link

@daveshirman I am also work pretty well in the same condition like you. But when I swipe and remove this notification message and didn't get this data anymore. Do u have any solution for this case.

@daveshirman
Copy link

daveshirman commented Nov 18, 2022 via email

@thiagotalma
Copy link

Please, someone responsible for the project, pay attention to this issue.

It is very important that it is possible to execute commands when ANY notification is received, regardless of whether the application is in foreground or background or even closed.

On Android I have this option. But I'm migrating my app to Flutter and I'm missing that option.

Flutter is becoming too relevant for the OneSignal package to be ignored.

cc:
@nan-li
@emawby
@tanaynigam
@iAmWillShepherd
@Jeasmine
@brayden-onesignal
@gdeglin
@jkasten2
@leemunroe
@niels-s

@KKimj
Copy link

KKimj commented Jan 5, 2023

Hello!

Do I need to use another push service to route to a specific page while clicking on a push message in Terminated state?

Or has anyone else solved it?
Thank you.

@emawby
Copy link
Contributor

emawby commented Jan 30, 2024

Closing issue as stale. If this is still happening in 2024 feel free to tag me to reopen

@emawby emawby closed this as completed Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

17 participants