我在使用内部onReceived(通知){},onOpened(openResult){} Onesignal事件时得到 this.handleNotification()/ this.setState()不是函数错误创建。下面是我的代码。 任何解决方案。我是否正确实施?
componentWillMount() {
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('opened', this.onOpened);
}
componentWillUnmount() {
OneSignal.removeEventListener('received', this.onReceived);
OneSignal.removeEventListener('opened', this.onOpened);
}
onOpened(openResult) {
try {
this.setState({ msgBody: openResult.notification.payload.body });
} catch (error) { }
}
onReceived(notification) {
OBJ.homeData.setNewMsgCount();
this.handleNotification('', '', '');
}
答案 0 :(得分:1)
您必须将上下文绑定为以下代码:
OneSignal.addEventListener('received', this.onReceived.bind(this));