OneSignal / onesignal-ngx

OneSignal Angular
Other
5 stars 5 forks source link

[Bug]: subscriptionChange not being called #38

Closed j-oppenhuis closed 1 year ago

j-oppenhuis commented 1 year ago

What happened?

subscriptionChange is not being triggered. I expect it to be called when permission has been granted and the web worker is loaded. Because of this we can't get the user id. We use this in a PWA, so we run it in Android and iOS, only after the app is closed and opened again we are able to get the user id.

The following issue seem to describe the same: https://github.com/OneSignal/OneSignal-Android-SDK/issues/749

What browsers are you seeing the problem on?

Chrome (Chromium), Safari

What operating system are you running?

PWA Android (and maybe iOS devices?)

Steps to reproduce?

// First init oneSignal
await this.oneSignal.init({
  appId: '{id}',
  autoResubscribe: true,
  allowLocalhostAsSecureOrigin: true,
  serviceWorkerParam: {
    scope: '/{scope}'
  },
  serviceWorkerPath: '/{path}'
});

// Listen to subscriptionChange
this.oneSignal.on('subscriptionChange', isSubscribed => {
  // This never gets called
  console.log('One signal subscription changed', isSubscribed);
  if (isSubscribed) {
    this.initAfterSubscription();
  }
});

const permission = await this.oneSignal.getNotificationPermission();
if (permission === 'denied') {
  return;
}

if (permission === 'default') {
  await this.oneSignal.showNativePrompt();
}

What did you expect to happen?

I expected to see the console log inside the subscriptionChange listener.

Relevant log output

No response

jkasten2 commented 1 year ago

@j-oppenhuis I believe this issue is fixed with the 2.0.0 release, however if there is still an issue in 2.0.0 please open a new issue.