如何在React Native中使用一个信号获得玩家ID



我正在尝试使用oneSignal。我遵循文档中的步骤。当我运行应用程序时,它应该根据我的index.js:中的代码来控制台设备信息

constructor(properties) {
super(properties);
// OneSignal.init("e353b33e-8b5f-4093-8a86-073b0504b5f2");
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('registered', this.onRegistered);
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);
}

当我打开控制台时,它没有显示函数OnId((中的设备信息。

有人能告诉我我做错了什么吗?我是新手,所以谢谢你的帮助

这在功能组件中对我有效

const data = await OneSignal.getDeviceState();
const player_id=data.userId;

我刚刚遇到这个问题,它很不清楚,但如果你检查文档,他们会说:

请注意,调用OneSignal.configure((会引发ids事件。

我刚刚在构造函数的末尾添加了OneSignal.configure((,现在它触发了OnId((。

最新更新