Wrap your code inside platform.ready() function.
import { NavController,Platform } from 'ionic-angular'; //import platform
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(private oneSignal: OneSignal,public navCtrl: NavController,public platform:Platform) { // add platform here
platform.ready().then(()=>{ //add this function
this.oneSignal.startInit('5d4fd62b-b9f8-4e41-9a89-7ea3b18af3de','470761651487');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);
this.oneSignal.handleNotificationReceived().subscribe((d) => {
// do something when notification is received
console.log("NOTIFICATION RECEIVED");
console.log(d);
});
this.oneSignal.handleNotificationOpened().subscribe((d1) => {
// do something when a notification is opened
console.log("NOTIFICATOIN OPENED");
console.log(d1);
});
this.oneSignal.endInit();
});
}
}