反应本机RN OneSignal.didSetNotification打开的处理程序不是函数

时间:2018-12-12 08:54:47

标签: react-native onesignal

当我在通知警报下方添加此代码时,出现以下错误:

  

ExceptionsManager.js:84未处理的JS异常:TypeError:RN   OneSignal.didSetNotification打开的处理程序不是函数

显然这行:

OneSignal.addEventListener('opened', this.onOpened)

当我删除该问题后,该问题消失了, 谢谢您的帮助

constructor(props) {
super(props)
   OneSignal.init("my ID");
   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) {
console.log("Notification received: ", notification);
}
onOpened(openResult) {
  console.log('Message: ', openResult.notification.payload.body);
  console.log('Data: ', openResult.notification.payload.additionalData);
  console.log('isActive: ', openResult.notification.isAppInFocus);
  console.log('openResult: ', openResult);
}
onIds(device) {
  console.log('Device info: ', device);
}

enter image description here

0 个答案:

没有答案