You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
const canRequestPermission = await OneSignal.Notifications.canRequestPermission();
if (canRequestPermission) {
showUserPrettyNotificationsUI();
// on Android versions < 13, you would see this UI even though you cannot prompt for permissions
}
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()
const hasPermission = await OneSignal.Notifications.getPermissionAsync();
const canRequestPermission = await OneSignal.Notifications.canRequestPermission();
// Only show UI if we DON'T have permission AND we CAN request permissions
// This fixes Android < 13 because hasPermission will be true
const shouldShowPrettyNotificationsUI = !hasPermission && 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
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
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
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
The text was updated successfully, but these errors were encountered: