Open mikemonaco opened 1 month ago
If i am not wrong, the purpose of canRequestPermission is to track the situation where user DENIES the notification permission since the permission alert dialog wont show up if its denied a couple of times. So i suggest you change your logic like this
const hasPermission = await OneSignal.Notifications.getPermissionAsync();
if (!hasPermission) {
showUIExplainingWhyYouNeedNotificationPermission()
const canRequestPermission = await OneSignal.Notifications.canRequestPermission();
if (canRequestPermission) { await OneSignal.Notifications.requestPermission(false) } else { await OneSignal.Notifications.requestPermission(true) } }
What's on your mind?
When calling OneSignal.Notifications.canRequestPermission() on Android version < 13, the return value always seems to be true. This may be misleading because you cannot request permission on older Android versions, they are granted by default. Notification permissions dialogs were added in Android version 13+.
For example, the following pseduo-code would produce an unfavorable outcome:
Since you cannot request permissions on Android version < 13, it would probably make sense to return false when calling canRequestPermission()
My current workaround is to check both getPermissionAsync() and canRequestPermission()
I'm not sure of the ideal solution for the SDK internally, since it may have other affects on iOS, but wanted to present this inconsistency to the developers of the OneSignal react native sdk.
Code of Conduct