reactjs - 如何在 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);
}
当我打开控制台时,它没有显示来自函数 onIds() 的设备信息。
有人可以告诉我我做错了什么吗?我是新手,所以感谢您的帮助
解决方案
我刚刚遇到了这个问题,还不清楚,但如果你查看他们说的文档:
请注意,调用 OneSignal.configure() 会导致 ids 事件触发。
我刚刚在构造函数的末尾添加了 OneSignal.configure(),现在它触发了 onIds()。
推荐阅读
- docker - XDEBUG 无法正常工作,但已安装并且日志显示“连接到客户端 :-)”
- html - 如何使用 Tabulator.js 计算时间
- ruby-on-rails - 如何修复 Rails Geocoder 中的错误“未定义方法”?
- tensorflow - TensorFlow 对象检测 API:如何隔离主干网络?
- javascript - 循环无限嵌套对象并构造字符串
- javascript - sinon依赖函数伪造
- sap - 通过将 SAP 表拆分为小块来复制它
- json - 在 vb.net 中获取令牌值
- c# - JSON web-api 上暴露的对象 - 如何阻止属性名称更改大小写?
- html - 为什么 HTML 超链接在我的子文件夹中不起作用?