Expo CLI 2.11.6 environment info:
System:
OS: macOS 10.14.3
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.10.1 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
IDEs:
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmGlobalPackages:
expo-cli: 2.11.6
Packages:
expo: 32.0.2
react: 16.5.0
react-native: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz
Device: iPhone XS Max, iOS 12.1.4
expo build:ioscurl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
"to": "ExponentPushToken[TOKEN]",
"title":"hello",
"body": "world",
"data": {"info": "test"}
}'
I expect the event listeners added using Notifications.addListener to be called in all these three situations: (ref: https://docs.expo.io/versions/latest/guides/push-notifications/#determining-origin-of-the-notification)
The function was only called in these two situations:
If the app was not open, and then opened by selecting the push notification, the function was not called.
From https://docs.expo.io/versions/latest/guides/push-notifications/#3-handle-receiving-andor-selecting-the-notification
import React from 'react';
import { Text, View } from 'react-native';
import { Notifications } from 'expo';
import { registerForPushNotificationsAsync } from './app/helper/PushNotification';
export default class App extends React.Component {
state = {
notification: {},
};
componentDidMount() {
registerForPushNotificationsAsync();
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
_handleNotification = (notification) => {
this.setState({ notification: notification });
};
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Origin: {this.state.notification.origin}</Text>
<Text>Data: {JSON.stringify(this.state.notification.data)}</Text>
</View>
);
}
}
Same issue as #3531 , cross-referencing.
Hi @hesyifei - sorry for the slow followup here. It appears that our docs may be wrong -- it looks like in this case for iOS the notification data is passed as props.exp.notification on the root app component rather than calling the notifications listener. Could you try reading that prop instead and let us know if that works? I will fix our docs if so.
Hmm, following up again it looks like this may be a bug on our side after all 馃 could you let us know if you're using a different entry point than the default (e.g. your main file is not called App.js)?
My main file is called App.js.
props.exp.notification is also empty when I open the app by clicking the notification.
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Origin: {this.state.notification.origin}</Text>
<Text>Data: {JSON.stringify(this.state.notification.data)}</Text>
<Text>Props: {JSON.stringify(this.props.exp.notification)}</Text>
</View>
);
}
this.props.exp also doesn't seem to contain anything related to the notification.
(#3526 removes mentions of props.exp.notification in the documentation. Also, this seems like a similar problem to #1691.)
Ok, thanks for the info. We're looking into this.
The issue happens with me too.
I have the same issue. Are there any known workarounds? Like moving back to an older SDK?
@esamelson did you have time to look into it? It is quite necessary functionality
Upvote... is this being addressed? It's a huge issue preventing us from fully rolling out these notifications for iOS.
Yeah this doesn't work on Standalone iOS. Knd of a pain in the ass - I was told Expo team will not be working on the rnf notification package any more if thats true whats the word for the future?
Sorry for the slow followup here! We're actively looking into this, not sure yet when we'll have a fix but hopefully soon.
Same issue
Hey all,
Good news. We've identified the problem and will be rolling out a fix soon!
Cheers!
The fix has been deployed to production. You'll need to rebuild your app with expo build:ios in order to get the fix. Apologies again for the inconvenience, and thanks all for bringing this to our attention!
Thanks!!!! For iOS now work fine
A hearty thank you for fixing this!
@AdamJNavarro and @esamelson What about people using stand alone?
@heyaj19 - the fix is for people using standalone apps. You'll need to run expo build:ios again to rebuild your standalone app in order to get the fix.
did the fix lead to triggering the callback listener or do you need to process. the App component's props?
-- ps, this happens when the user did select the notification. (just saying, it might not be clear in retrospect)
I actually have this issue on Android. If the standalone app is closed, the listener added with Nofifications.addListener is not being called when a notification is received.
Edit: Actually, I am a bit confused by the doc. Is it not meant to trigger the listener when the app is closed?
@divonelnc I'm also a bit confused, did you manage to find the answer?
@pavlo-paliychuk-insighty Yeah, unfortunately, listeners added with Notifications.addListener are only meant to be called while the app is running. A closed app will only run the default expo notification behavior.
@divonelnc it's a shame, I'm trying to figure out what the best approach for handling notification in the closed app would be (as I'm having some loading upon app launch to get through). Currently exploring the "props.exp.notification" option, really hope it works)
@pavlo-paliychuk-insighty
Hey, did you manage to find a solution? Did props.exp.notification work for you?
Hey guys. I see, that this issue is closed. But for me, it is still not possible to get Notification data, when opening the app built with expo from a notification.
Can anyone confirm, that this issue is resolved for your project?
@mtshv I can cofirm it works correctly. You can access notification data by registering callback in componentDidMount method of your root component. It is important to register it in this very method.
import { Notifications } from "expo";
export class App extends React.Component {
public componentDidMount() {
Notifications.addListener((notification) => console.log(notification));
}
}
I face the same issue in 35 SDK for a standalone iOS app. When a notification comes and the app is open, app does not receive any info about the notification.
If the user presses the notification the data comes. Has anyone solved it in "sdkVersion": "35.0.0"?
Also facing the same issue as on SDK 35.0.0...
Several points here:
-While the app is closed on iOS, receiving a push notification does not trigger any events on the app itself.
-While the app is open and foregrounded on iOS, pressing/interacting with the dropdown notification returns the wrong origin data (should be "selected", but instead "received").
Hey @jaaamesk, for your first point- receiving a notification itself won't trigger the notification listener. The app will need to be open, or the notification selected (either when it comes in and shows as a banner, or through the notification center). For your second point, that is the desired behavior. It's received if the notification was received while the user was in the app
Hi @cruzach, from the docs:
Push was received when App is open and foregrounded, origin will be... 'received'.
I get 'received' event in these circumstances only when users taps the notification.
Maybe the desired behavior maybe changed? It makes more sense to get the event "received" when notification is really received and get the event "selected", when it is actually selected.
From my point of view, now notifications serves little purpose. We developed a task management app. When task is created, notification is sent to the phone. So app should update its state with new data (photos, description, to-do list, etc.). It does not matter if app is the background, foreground or not opened at all.
With existing logic of Expo notifications what happens is users get the notifications and each time they have to update the state manually.
For example if you receive a message in Messenger, the message thread is updated and it does not matter if app was is the background, foreground or not opened at all.
How can we get the same behavior with Expo?
Push was received when App is open and foregrounded, origin will be... 'received'.
I get 'received' event in these circumstances only when users taps the notification.
not sure what you mean here. If the app is open and foregrounded, the expected behavior is received, which is what's happening in your case. You can see the different cases and results here https://docs.expo.io/versions/latest/guides/push-notifications/#determining-origin-of-the-notification
Hey @cruzach , thank you for the response.
So I have noticed that Android and iOS handles the notifications differently:
For android, when a notification is received (while app is open and foregrounded), the origin is set as "received" initially. If and when I click the notification, a second trigger is sent with the origin "selected".. This is not the case on iOS, since a "received" doesn't get triggered until the notification is pressed/interacted with... No "selected" origin when pressing the notification.
I have created a front end script that can handle the messages somewhat successfully, but it definitely isn't foolproof. For instance, on iOS, even if the app is open (but in the background), the notification is not "saved" on the app (I have achieved this by using the Notification event listener as a trigger to save in the redux store). Android on the other hand, if the app is open but in the background, it will trigger the event listener, and add it to the redux store..
Sorry I might be rambling on a bit, but I wanted to share my findings, and see if anyone might have a solution to this (or possibly a fix/update with expo in the future?).
Thank you
@cruzach forgot to mention, I was writing about iOS. I have the same behavior.
Hello @paul-paliychuk-mason
I am facing similar issue, NotificationListener is called when app is open but not when app is closed. I want to access notificaton data in app when app is closed and opened through notification click.
Hi @zainulogna, I believe this is a known issue/missing functionality... I don't want to speak on behalf of the developers, but this page (https://docs.expo.io/versions/latest/guides/push-notifications/) under the section "Determining origin of the notification" explains that when an "App was not open, and then opened by tapping the home screen icon" it will trigger no notification, which is essentially what we are encountering.
Hope this helps
When android standalone( not managed) app is background (not closed), I can see "received" notification arrived in log but heads up notification not displayed then user cannot select notification.
Android Studio Logcat follows.
2020-01-12 14:02:29.954 15063-15063/? D/Launcher.NotificationListener: onNotificationRemoved : StatusBarNotification(pkg=com.*.android user=UserHandle{0} id=-387486133 tag=@/ccon key=0|com..android|-387486133|@/ccon|10321: Notification(channel=CCON pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x10 color=0xff060034 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)) listener : null
2020-01-12 14:02:30.398 6010-25006/? E/NotificationService: No vibration for canceled notification : 0|com..android|-387486133|@*/ccon|10321
Hi @zainulogna, I believe this is a known issue/missing functionality... I don't want to speak on behalf of the developers, but this page (https://docs.expo.io/versions/latest/guides/push-notifications/) under the section "Determining origin of the notification" explains that when an "App was not open, and then opened by tapping the home screen icon" it will trigger no notification, which is essentially what we are encountering.
Hope this helps
Did this work for Android ?
Hi Everyone,
We are blocked to release app , as on Android , it doesnt trigger notification , when app was closed and launched by tapping on notification. It works when app is already running. Was anyone able to find any workaround for android ? It works on iOS . We are using latest SDK 36.
@mtshv I can cofirm it works correctly. You can access notification data by registering callback in
componentDidMountmethod of your root component. It is important to register it in this very method.import { Notifications } from "expo"; export class App extends React.Component { public componentDidMount() { Notifications.addListener((notification) => console.log(notification)); } }
Hi ,
What SDK are you using ? Did this work for Android ?
Push was received when App is open and foregrounded, origin will be... 'received'.
I get 'received' event in these circumstances only when users taps the notification.not sure what you mean here. If the app is open and foregrounded, the expected behavior is
received, which is what's happening in your case. You can see the different cases and results here https://docs.expo.io/versions/latest/guides/push-notifications/#determining-origin-of-the-notification
Hi @cruzach ,
For Android , when app is launched by tapping on notification , it is not triggering handle notification method. It works when app is running on next trigger it works. And for iOS , it works even for the first time , when app gets launched , listener gets added and handle notification is triggered for iOS. But for Android it only triggers when app is running. In documentation(https://docs.expo.io/versions/latest/guides/push-notifications/) , it mentions this behavior in comment section.
Can you suggests , if there is any workaround for android or this is expected behavior ?
@aeshashah the Notification listener should fire if the Notification is selected, as it says in the docs:
App was not open, and then opened by selecting the push notification | 'selected'
-- | --
If you're not seeing this behavior, I suggest creating a reproducible demo
@aeshashah the Notification listener should fire if the Notification is selected, as it says in the docs:
App was not open, and then opened by selecting the push notification 'selected'
If you're not seeing this behavior, I suggest creating a reproducible demo
@cruzach , thanks for replying.
Here at comment section in document https://docs.expo.io/versions/latest/guides/push-notifications/ , it says this function will fire on the next tick after the app starts :
We are seeing this behavior as mentioned in comments below on Android. Is this expected ? or it should work for Android ?
componentDidMount() {
registerForPushNotificationsAsync();
// Handle notifications that are received or selected while the app
// is open. **If the app was closed and then opened by tapping the
// notification (rather than just tapping the app icon to open it),
// this function will fire on the next tick after the app starts
// with the notification data.**
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
Can you suggest , where should we upload demo ?
the behavior described in the comment is the correct behavior
the behavior described in the comment is the correct behavior
Thanks @cruzach . Can you please confirm this behavior ? For Android phone , when app was closed and notification is received , user taps on notification , app is launched and handle notification listener is registered. But handle notification function is not triggered.
Now , next time on tapping notification , it triggers handle notification function ( as app is already opened).
Appreciate your quick reply and help.
Ah I understand your issue now, I think it's the same as what's reported in https://github.com/expo/expo/issues/6529
@cruzach , Thanks . Yes , we are having same issue as mentioned in #6529. Is this working or this is open bug ?
@cruzach , we are also using expo 36. Is there any workaround for this issue. We are actually blocked to do the release of our app , appreciate your input and suggestions.
I'm trying on Android:
I still not catching notifications on the listener when the app is closed and I tap on the notification.
Any news about that? is there a new issue created for that?
I still have this issue
Same with expo notification bare, Notifications.addNotificationReceivedListener
Doesn't register when app is in background.
I'm facing the same issue. Did you manage to solve it somehow?
I have been stuck on this issue for a while now has anyone found a a fix? On Android when the app is foregrounded or in backgrounded the listener works but when the app is closed the listener does not work at all? is this a bug? does anyone have a workaround? @cruzach
Hi For IOS when app is foregrounded or Back grounded my Notifications.addListener is not getting called. For android it is wroking fine as expected
This is still an issue on Android, Expo SDK 37.0
Please resolve this at least in the next SDK release guys. Would be much appreciated.
FIXED! -> https://github.com/expo/expo/issues/6529#issuecomment-613099968
I'm having the same problem on both Android and iOS on expo 37.0.0
When click the push notification, if app is open, triggers the handle, otherwise it just opens the app and the function is not fired and nothing happens.
I Try moving from functional component to a React.Component thinking thats maybe the issue but still the same behavior.
The only way it "kinda works" is if I keep the expo app opened and then click the push notification, this way the app opens and fire the handle function as expected.
This is still an issue on Android, Expo SDK 37.0
Please resolve this at least in the next SDK release guys. Would be much appreciated.
check this, https://github.com/expo/expo/issues/6529#issuecomment-613099968
in my case it was the dark mode on my Android
if my app is close so i can trigger some functions ?
now i just get push notifications messages when app is close and i see it, but i want also fire some functions that also be fired when the app is close.. how do i do it ?
This is still an issue on Android, Expo SDK 37.0
Please resolve this at least in the next SDK release guys. Would be much appreciated.check this, #6529 (comment)
in my case it was the dark mode on my Android
Omg Thank you so much
Android, Expo 38.0.0. Notifications.addNotificationReceivedListener is not firing when the app is in background and a notification is received. userInterfaceStyle: "automatic" did not help either.
Hi everyone, the original issue from this thread was fixed last year when the issue was closed. If you are seeing similar issues with different symptoms, this thread is not a good place to report a problem or get help. Please open a new issue and fill out the template fully, including clear and easy steps we can follow to reproduce your case. Thank you!
Most helpful comment
I actually have this issue on Android. If the standalone app is closed, the listener added with
Nofifications.addListeneris not being called when a notification is received.Edit: Actually, I am a bit confused by the doc. Is it not meant to trigger the listener when the app is closed?