Ionic 4 onesignal playerid(unique id) null when no internet connection

I am using onesignal push notification in ionic 4 i am getting playerid (unique id ) for individual device when i am login the application.

Suppose i try to login without internet connection ,after fails i am connect internet and trying to login the application i am getting playerid (unique id ) NULL. Why?

my code is below,

this.oneSignal.startInit('my app id', 'firebaseid');


// Notifcation was received in general
this.oneSignal.handleNotificationReceived().subscribe(data => {
  let msg = data.payload.body;
  let title = data.payload.title;
  let additionalData = data.payload.additionalData;

this.oneSignal.handleNotificationOpened().subscribe(data => {
  let additionalData = data.notification.payload.additionalData;



this.oneSignal.getPermissionSubscriptionState().then(status =>{



i am using this code app.component.ts and after successfully login. i don’t know how to solve this,please help to solve the problem.

Answer is,

this.oneSignal.addSubscriptionObserver(function (state) {
  if (!state.from.subscribed && {
   // get player ID