Hi Community, any one facing issue when calling onesignal library the script like skip from executed or not properly running? Because i facing some issue on onesignal that certain phone look onesignal no properly running so we cannot get the deviceid. certain phone working fine. i still don’t have clue what happen.
Below is my code.
await this.oneSignal.startInit(environment.onesignal.appId, environment.onesignal.googleProjectNumber);
this.oneSignal.setSubscription(true);
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
this.oneSignal.enableSound(true);
this.oneSignal.enableVibrate(true);
await this.oneSignal.endInit();
this.oneSignal.getIds().then((data) => {
console.log('iddddd', data);
localStorage.setItem('fcm', data.userId);
}).catch((e) => {
console.log(e);
});
thank you
Try this:
this.platform.ready().then(() => {
this.oneSignal.getIds().then((data:any) => {
console.log('iddddd', data);
localStorage.setItem('fcm', data.userId);
}).catch((e) => {
console.log(e);
});
});
Don’t forget to import the Platform
and add it to your constructor.
Yes, actually is similar like your suggestion here the full one:
this.platform.ready().then(() => {
this.statusBar.backgroundColorByHexString('#ffcd40');
this.splashScreen.hide();
setTimeout(async () => {
await this.oneSignal.startInit(environment.onesignal.appId, environment.onesignal.googleProjectNumber);
this.oneSignal.setSubscription(true);
this.oneSignal.enableSound(true);
this.oneSignal.enableVibrate(true);
await this.oneSignal.endInit();
this.oneSignal.getIds().then((data) => {
console.log('iddddd', data);
localStorage.setItem('fcm', data.userId);
}).catch((e) => {
console.log(e);
});
},5000);
});
and also its not go to catch part to show error. its like just skipped.
this.platform.ready().then(() => {
this.statusBar.backgroundColorByHexString('#ffcd40');
this.splashScreen.hide();
this.oneSignal.startInit(environment.onesignal.appId, environment.onesignal.googleProjectNumber);
this.oneSignal.setSubscription(true);
this.oneSignal.enableSound(true);
this.oneSignal.enableVibrate(true);
this.oneSignal.endInit();
setTimeout(() => {
this.oneSignal.getIds().then((data) => {
console.log('iddddd', data);
localStorage.setItem('fcm', data.userId);
}).catch((e) => {
console.log(e);
});
},5000);
});
Try this change in your code.