应用程序处于后台时,OneSignal onReceived侦听器操作

时间:2018-06-02 19:06:58

标签: react-native react-native-ios onesignal

我希望在收到通知时存储通知数据。这在应用程序打开时工作正常,但如果应用程序在后台,则onReceived不会被触发,因为componentWillUnmount会删除侦听器。

这就是我现在所拥有的。

componentWillMount() {

  OneSignal.addEventListener('received', this.onReceived);
  OneSignal.addEventListener('opened', this.onOpened);
  OneSignal.addEventListener('ids', this.onIds);
}

componentWillUnmount() {
    OneSignal.removeEventListener('received', this.onReceived);
    OneSignal.removeEventListener('opened', this.onOpened);
    OneSignal.removeEventListener('ids', this.onIds);
}

onReceived = (notification) => this.props.dispatch(
  addNotification({"id": notification.payload.notificationID, "text": notification.payload.body, "url": notification.payload.additionalData.somedata})
)

有什么建议我可以在应用程序处于后台时使其工作吗?

0 个答案:

没有答案