2

I am trying to use Expo.Notifictions.addListener in my component (on iOS standalone build), but it doesn't fire although notifications are successfully received.

addListener() is placed inside componentDidMount() function.

Expo.Notifications.addListener(this.handleNotification);

handleNotification = () => {
  this.setState({
    something: 3,
  });
};
5
  • Could you clarify what you mean by "... but it doesn't fire although notifications are successfully received."? You mean that when the app is foregrounded the push notification's not shown? Also, what's the SDK version you're using? Jan 25, 2019 at 12:38
  • @BrunoEduardoDAngelodeOlive Yes, I mean that the notification is sent to my device, but the listener is not reacting when the app is foregrounded. I'm using the version: "28.0.0".
    – runha
    Jan 26, 2019 at 13:14
  • I use the same version in my app and the listener fires but I don't see any notifications when the app is in the foreground (code's executed though). Have you tried checking if that's the same for you? Also, seems like older SDKs might be bugged (forums.expo.io/t/…) try updating to v32.0.0 and see if that fixes your issue. Jan 26, 2019 at 13:24
  • If the application is running in the foreground, iOS won't show a notification banner/alert. That's by design (Android for example shows notification in the status bar on the top, and that's not the case by iOS). That's why I need the listener, to render the component or to inform the user that the notification came. If your listener is working, can you please put your code example? I also think that the problem is older SDK.
    – runha
    Jan 26, 2019 at 13:32
  • Sorry but I can't, it's code for the proprietary app I develop at work. I'm not at home right now, but I'll try to get you a working iOS example ASAP ok? Jan 26, 2019 at 13:36

1 Answer 1

2

You are not adding callback into ur addListener function.

componentDidMount(){
    Notifications.addListener(notification => {
      console.log(notification);  
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.