Ionic 4 OneSignal getIds大延迟

时间:2019-06-06 15:25:24

标签: angular ionic-framework ionic4 onesignal

我正在使用Ionic 4(Angular),其中一个信号用于推送通知(OneSignal Cordova插件,一个信号通过npm)。 当我使用getIds()函数时,获取用户ID(userId和令牌)的时间很长,大约需要30秒到2分钟的时间。在某些情况下,这些ID不会返回。

我尝试从生命周期切换,在initializeApp之前或之后检索,我尝试使用addSubscriptionObserver和addPermissionObserver。所有这些都具有相同的结果,从30秒到2分钟的巨大延迟,在某些情况下不会返回。

这是我目前在Ionic 4(Angular)的app.component.ts中的initializeApp()(在构造函数中调用initiliazeApp)内部使用的代码:

this.oneSignal.startInit(this.onesignal_appid, this.firebase_senderid);
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);

this.oneSignal.handleNotificationReceived().subscribe((res) => {
    // do something when notification is received
});

this.oneSignal.handleNotificationOpened().subscribe((res) => {
    // do something when a notification is opened
});

this.oneSignal.endInit();

this.getNotificationPlayerIds()
    .then((ids) => {
        console.log('first get ids: ', ids);
        this.notificationPlayerIds = ids;
    })
    .catch((e) => {
        console.log('first get ids error: ', e);
    });

  getNotificationPlayerIds() {
    return new Promise((resolve, reject) => {
      if (this.platform.is('cordova')) {
        this.oneSignal.getIds()
          .then((ids) => {
            resolve(ids);
          })
          .catch((e) => {
            reject(e);
          })
      }
    })
  }

我希望这些ID尽快返回,以便可以将这些数据保存在数据库的用户对象中。 代码中是否有任何不正确的东西导致此问题,或者这确实是插件/节点模块(npm)问题?我什至在离子团队上开了一个问题,但没有成功。 https://github.com/ionic-team/ionic-native/issues/3046

谢谢!

1 个答案:

答案 0 :(得分:0)

由于网络问题,延迟问题很可能是设备获得播放器ID的问题。打开详细日志记录并检查logcat或Xcode日志应该可以查明您的问题。