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

时间:2018-11-23 02:55:21

标签: reactjs react-native onesignal

我正在尝试使用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()函数的设备信息。

有人可以告诉我我在做什么错吗?我是新来的,所以谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

我刚刚遇到了这个问题,目前还不清楚,但是如果您查看文档,他们会说:

  

请注意,调用OneSignal.configure()会导致ids事件触发。

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