【发布时间】:2018-11-21 13:19:33
【问题描述】:
当用户在启动应用程序时接受通知时,我需要存储 playerID。这是在 app.component.ts 中的 initializeApp 函数上。
我可以获取 playerID(我可以使用 console.log 显示它)但是当我尝试将其设置为本地存储时,它不起作用。这里是我的 app.component.ts:
initializeApp() {
if (this.platform.ready()) {
this.platform.ready().then((res) => {
console.log(res);
if (res == 'cordova') {
this.oneSignal.startInit('xxx-xxx-xxx', 'xxx');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);
this.oneSignal.getIds().then((ids) => {
this.nativeStorage.setItem('playerID', ids.userId);
});
this.oneSignal.handleNotificationReceived().subscribe((message) => {
// do something when notification is received
});
this.oneSignal.handleNotificationOpened().subscribe(() => {
// do something when a notification is opened
});
this.oneSignal.endInit();
// console.log(this.oneSignal.startInit('b8320a40-f565-4593-b9aa-d98b580bf8e1', '323509745034'));
// this.oneSignal.getIds().then(response=>{
// console.log(response);
// });
// this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);
// this.oneSignal.handleNotificationReceived().subscribe(() => {
// });
// this.oneSignal.handleNotificationOpened().subscribe(() => {
// });
// this.oneSignal.endInit();
}
});
}
}
【问题讨论】:
标签: typescript ionic-framework push-notification ionic3 onesignal