Ionic 4 OneSignal getIds大延迟 [英] Ionic 4 OneSignal getIds big delay

查看:65
本文介绍了Ionic 4 OneSignal getIds大延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Ionic 4 (Angular) with one signal for a push notification (OneSignal Cordova Plugin and one signal via npm). When I use the getIds () function I have a long delay to get the user ids (userId and token), it takes between 30 seconds and 2 minutes. In some cases, these ids do not come back.

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

I tried switching from lifecycle, retrieving before or after initializeApp, I tried using addSubscriptionObserver and also addPermissionObserver. All have the same result, this great delay from 30 seconds to 2 minutes and in some cases does not return.

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

This is the code I am currently using inside the initializeApp() (the initiliazeApp is called in the constructor) in the app.component.ts of Ionic 4 (Angular):

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

I hope these ids return as soon as possible so that I can save this data in the user object in the database. Is there anything in the code that is incorrect and causes this or is it a really plugin/node module (npm) problem? I even opened an issue on the ionic-team, but without success. https://github.com/ionic-team/ionic-native/issues/3046

谢谢!

推荐答案

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

The delay issue is most likely a problem with the device getting a player id due to a networking issue. Turning on Verbose logging and checking the logcat or Xcode log should pinpoint your issue.

这篇关于Ionic 4 OneSignal getIds大延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆