【发布时间】:2026-02-10 16:15:01
【问题描述】:
我正在使用 Ionic 4 (Angular) 和一个用于推送通知的信号(OneSignal Cordova 插件和一个通过 npm 的信号)。 当我使用 getIds () 函数时,我有很长的延迟来获取用户 ID(userId 和 token),需要 30 秒到 2 分钟。在某些情况下,这些 id 不会回来。
我尝试从生命周期切换,在 initializeApp 之前或之后检索,我尝试使用 addSubscriptionObserver 和 addPermissionObserver。都具有相同的结果,这种从 30 秒到 2 分钟的巨大延迟,在某些情况下不会返回。
这是我目前在 Ionic 4 (Angular) 的 app.component.ts 中的 initializeApp() 中使用的代码(在构造函数中调用了 initiliizeApp):
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)问题?我什至在 ionic-team 上打开了一个问题,但没有成功。 https://github.com/ionic-team/ionic-native/issues/3046
谢谢!
【问题讨论】:
标签: angular ionic-framework ionic4 onesignal