-
Notifications
You must be signed in to change notification settings - Fork 86
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
Comments
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. |
@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 |
@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 cool, can you show me how you did it? because i don't understand much of native code =/ |
@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. |
@hypnocill it worked for me, before i was using it inside a stack navigation, now i put it on the splash screen, thanks. |
On iOS the problem seems to persist even putting the listener as the first instruction in the App.js |
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.
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!
The text was updated successfully, but these errors were encountered: