Background notification handling
complete
Lars Moelleken
Has someone a working example for react native navigation, currently it seems not to work for eas builds if the app was killed, or? 馃 https://github.com/expo/expo/issues/14078
Charlie Cruzan
complete
This feature was added in SDK 42, which is now available for beta! https://blog.expo.io/expo-sdk-42-beta-is-now-available-e505770389e7
B
Brian Walker
Charlie Cruzan: I am not sure why, but in a standalone build the background notification handling isn't working for me. Works well when the app runs in Expo Go.
Charlie Cruzan
Brian Walker: That could be an issue with credentials (if push notifications aren't working at all)
B
Brian Walker
Thank you for your reply Charlie Cruzan. Seems the issue was that I wasn't initializing the handlers "soon enough" after application start. Tweaking where this code executes resolved the problem.
Reference (your comment as well :)
Tiago Palmas
im facing the same problem and didnt find a solution yet. Did you find a solution for this bug ?
Matt Gaspar
This sounds more like a bug. I found an open issue on Github describing this issue. I posted a link to this page and the video.
Random(chris)
Hi I start receiving notification on background from my app. Have the Expo team changed something?
Mohammad H
It's already possible in expo. When people clicks on your notification, you'll receive an event and can redirect to wherever you want. You can add any tracking info in your notification payload in data stanza
Jozef Vojt谩拧
Mohammad H: But you are able to handle event only if user receive notification while he is in app. If app is closed, and you click it, event is not fired after app starts, so you cannot handle data from notification
Mohammad H
Jozef Vojt谩拧: I'm pretty sure that's what I'm doing.
Notification received -> user clicks on it -> it opens app with event info -> i take action in app based on notification event data. i can verify my code and let you know what it does!
Jozef Vojt谩拧
Mohammad H: can you mail me with example code, please? jozef@vojtas.io I've been not able to handle event after clicking notification with data.
Mohammad H
Jozef Vojt谩拧: sure, check this out which is stripped down version of my code https://gist.github.com/thehungrycoder/fb63a293acb32934dd492257ef5c26e0
Jesus Gil
Jozef Vojt谩拧: I am with Mohammad on this, you can handle notifications in all cases... Also, background notifications are something else: https://expo.canny.io/feature-requests/p/silent-push-notifications
Jozef Vojt谩拧
Mohammad H: Finally had time to go and implement, handler is called only if app is opened (foreground, background).
But once clicking on notification while app is closed, handler cannot handle notification (so I'm not able to redirect user to chat dialog as example): https://drive.google.com/open?id=165VuHx3qRQuwZzPS37mDmUJKQjMQ-sxk
Chris Geirman
Isn't this just deep linking?
Andrew McAuliffe
Chris Geirman: No. I believe Jozef is referring to what are sometimes called "silent notifications" or "data only notifications". Basically, sending data to an app such as "Conversation thread 123456 has new content" without sending an actual push notification to the app.
Chris Geirman
Andrew McAuliffe: Ah, so you can add a badge (or dot) to that thread? Gotcha!
Jozef Vojt谩拧
Andrew McAuliffe: What I'm talking about is actual push notifications. Once you send push notification (with data in payload), there's 2 possible scenarios.
- User has opened app. You are able to handle it with event listener, so you can handle notification with received data.
example: data: {chatId: '123456', lastMessage: 'test message'}
in this scenario you need to handle notification in app (example from our app: https://imgur.com/a/NfCRv69 notification is oriented at the top of screen). Based on received data object you are able to insert last message, and onClick will redirect to screen with chat dialog by considering chatId from data object.
- User is outside of app and will receive normal system notification. In body is something like "You received new message from user XXX", but you are not able to handle this notification. After clicking on notification event for notifications will not be fired with data as in scenario n. 1. So it will just open app, that's all.
Jesus Gil
Jozef Vojt谩拧: In your second example, when the App is NOT open or is in the background you can handle the notification with a data object no problem... Background notifications are something else, ( silent notifications ) that don't require user permissions.
Jozef Vojt谩拧
In video I'm showing all 3 scenarios
- Foreground (00:00 - 00:22)
- Background (minimalised) (00:27 - 00:40)
- Closed app (00:50 - 01:10) - not working
Dimitri KOPRIWA
Jozef Vojt谩拧: it seems to work when the app is closed...
Andrew McAuliffe
Dimitri KOPRIWA: In Jozef's third scenario (when the app is closed), the debug modal is not appearing after the user taps the notification and the app loads up. This is the problem; the notification handler does not seem to be running.
I am experiencing the same issue on my Android app after upgrading to Expo 39.