OneSignal-Cordova-SDK
OneSignal-Cordova-SDK copied to clipboard
[Bug]: Undefined device state in IOS
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
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?
I had a similar issue, getDeviceStatus() returned undefined. Thanks to this post I downgraded to ver 3.0.4 and it worked again.