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

'handleNotification' not working from killed app state #97

Open
hypnocill opened this issue Jun 21, 2022 · 7 comments
Open

'handleNotification' not working from killed app state #97

hypnocill opened this issue Jun 21, 2022 · 7 comments

Comments

@hypnocill
Copy link

hypnocill commented Jun 21, 2022

When I receive a notification on Android, 'handleNotification' is called when app is in foreground and in background but when the app is killed, 'handleNotification' is never called.

I have a SplashScreen and I followed the README. The intent extras seem to be passed correctly. This is the SplashScreeActivity where I log "Log.d("intent URI", intent.toUri(0));' and the output contains the notification data I sent. Yet the 'handleNotification' is never called.
Screenshot 2022-06-21 at 15 57 27

Update: I removed the Splash Screen and it still doesn't work

Also, when (if) this works, how to differentiate between when this function is called (if app was killed or in foreground), relates to: #87

Please, @Humni let me know if you have any idea how to get this to work since it's important to get the data from the notification in order to navigate in the app based on that.

Update: Calling .setInstanceId() at a very early stage of the app (first thing in App.tsx) seems to fix that for Android. For iOS, the issue remains

Thank you!

@hypnocill hypnocill changed the title handleNotification when notification opens the app from killed state 'handleNotification' not working from killed app state Jun 21, 2022
@leonardo409188
Copy link

leonardo409188 commented Jun 22, 2022

For me too, I'm using Expo bare workflow and when I get the notification with the app killed, it just opens the App and doesn't call the RNPusherPushNotifications.on function.

@hypnocill
Copy link
Author

@leonardo409188 Ah, I see. As mentioned, I logged the notification data and it's present when the app is opened from killed state. When I have enough time, I'll try to debug it further and see if I can understand why the notificationEvent is not emitted from native to js.

Meanwhile, any clues will be helpful. Thank you @codynguyen @b8ne

@hypnocill
Copy link
Author

hypnocill commented Jun 25, 2022

@leonardo409188 I found what the problem was, seems like a race condition. The 'notification' event from native when opening the app from killed state via notification was fired before the 'notification' event listener was added in JS.

I had to add directly DeviceEventEmitter.addListener("notification", callback) for Android only at very early stage in my app to catch the notification, then add a timeout to make sure my app is properly loaded, then emit a custom event for this particular case like DeviceEventEmitter.emit('android_notification') and for Android, in react-native-pusher-push-notifications JS 'notification' listener, for Android I'd only listen to iOS.

Seems like a nasty workaround though and I'd be happy to have a better way of dealing with this.

@hypnocill hypnocill reopened this Jun 25, 2022
@leonardo409188
Copy link

@hypnocill cool, can you show me how you did it? because i don't understand much of native code =/

@hypnocill
Copy link
Author

@leonardo409188 The last thing I did was calling just .setInstanceId and then on('notification', ...) listener as early as possible -first thing in App.js and it seems to catch the notification from killed state for Android.

@leonardo409188
Copy link

@hypnocill it worked for me, before i was using it inside a stack navigation, now i put it on the splash screen, thanks.

@p4ever
Copy link

p4ever commented Jun 14, 2023

On iOS the problem seems to persist even putting the listener as the first instruction in the App.js

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