OneSignal-Cordova-SDK icon indicating copy to clipboard operation
OneSignal-Cordova-SDK copied to clipboard

[Bug]: Undefined device state in IOS

Open anonimitoraf opened this issue 2 years ago • 2 comments

What happened?

We use the Cordova plugin to power our Ionic/Capacitor app. For a long time, we've been using ver 3.0.4 but recently, we had to upgrade to 3.3.0 for an essential bug fix.

In 3.0.4, for IOS, to get the current notification permission, we used to simply call OneSignal.getDeviceState((state) => ...)) where state.notificationPermissionStatus is defined as one of the PermissionStatus values.

Upon upgrading to 3.3.0, OneSignal.getDeviceState((state) => ...)) always returns a state where notificationPermissionStatus is undefined. I've also tried 3.1.1 (which is the exact version that contains the fix we needed): same result.

Is this expected? Are there new prerequisites for state.notificationPermissionStatus to be filled in? Are there better ways to get the current notification permission state? I see that we can potentially use the hasNotificationPermission state but is there a way to distinguish between "denied" vs "not yet prompted"?

Steps to reproduce?

1. Install ver 3.3.0 of the OneSignal Cordova plugin into an Ionic/Capacitor project (https://documentation.onesignal.com/docs/cordova-sdk-setup)
2. Invoke `OneSignal.getDeviceState` and log the callback value
3. Notice that the state is missing `notificationPermissionStatus`. For example:

{"userId":"REDACTED","pushToken":"REDACTED","pushDisabled":false,"subscribed":true,"emailSubscribed":false,"smsSubscribed":false,"hasNotificationPermission":true}

What did you expect to happen?

I expected OneSignal.getDeviceState to give me a state with notificationPermissionStatus defined

OneSignal Cordova SDK version

3.3.0 (but also happens in 3.1.1)

Which platform(s) are affected?

  • [X] iOS
  • [ ] Android

Relevant log output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

anonimitoraf avatar Dec 14 '22 12:12 anonimitoraf

Yep absolutely right, tested on 3.3.1, now there's no way to distinguish denied vs not requested. And starting from Android 13, we have to distinguish this status in Android too since we're started requesting notification permission. Any updates on that?

dmitry-salnikov avatar May 11 '23 12:05 dmitry-salnikov

I had a similar issue, getDeviceStatus() returned undefined. Thanks to this post I downgraded to ver 3.0.4 and it worked again.

agulab avatar Jun 28 '23 13:06 agulab