2

I am building an react-native app. I have a background android service that receives a push notification. I need to store the notification information(title, description...) on a react-native database or in asyncstorage... because in my app I have a page that shows all the notifications. I need that If my app is on background and i receive a notification, when the user open the app the page shows this information. How I can do this?

I try to store the notification on the same database that react-native uses but I can't store the data on the android service. Please, help me.

J. Alan
  • 51
  • 2

2 Answers2

0

Did you try exploring these.

    componentWillMount() {
    Linking.addEventListener("url", this.handleOpenURL);
    OneSignal.addEventListener("ids", this.onIds);
    OneSignal.addEventListener("received", this.onReceived);
    OneSignal.addEventListener("opened", this.onOpened);
  }

And in oneReceived event listener you can store data in async storage received from push notification.

onReceived(data) {
    this.props.setData(data);
  }

In set data you can have your logics to store data.Well i must say push notifications are not used to fetch data and to store and then to render.These provide just little information to open specific screen .Like i received a notification related to deals.Then pressing upon will automatically opens deals screen through linking not the home page of app.For your case you can send the request on that specific page to fetch data.

Abdul Basit Mangat
  • 1,112
  • 9
  • 18
0

Yes, but when you close the app and after this, someone sends one push notification, the event received and opened etc don't do nothing. I tried to make a custom native module that receives this info and try to send an Event. I followed this guide:

https://facebook.github.io/react-native/docs/native-modules-android#sending-events-to-javascript

But it don't works, always returns "sendEvent called before bundle loaded" java.lang.NullPointerException.

J. Alan
  • 51
  • 2