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 I request notification permission and deny the dialog twice, then check returns that I can still request, but request returns that user denied and cannot be requested again, so they conflict with each other.
I tried to use check and request apis and checkNotifications and requestNotifications api
request notification permissions twice and deny them, then check for permissions and you'll get that DENIED instead of expected BLOCKED
Here is a video:
Screen.Recording.2023-12-05.at.10.11.45.PM.mov
Reproducible sample code
import{View,Button}from'react-native';import{check,checkNotifications,PERMISSIONS,request,requestNotifications,RESULTS,}from'react-native-permissions';functionApp(){return(<Viewstyle={{flex: 1,alignItems: 'center',justifyContent: 'center',gap: 32,}}><Buttontitle="check notifications"onPress={checkNotificationPermission}/><Buttontitle="request notifications"onPress={requestNotificationPermission}/><Buttontitle="check notifications2"onPress={checkNotificationPermission2}/><Buttontitle="request notifications2"onPress={requestNotificationPermission2}/></View>);}exportdefaultApp;functioncheckNotificationPermission(){checkNotifications().then(({status})=>{switch(status){caseRESULTS.UNAVAILABLE:
console.log('This feature is not available (on this device / in this context)',);break;caseRESULTS.DENIED:
console.log('The permission has not been requested / is denied but requestable',);break;caseRESULTS.LIMITED:
console.log('The permission is limited: some actions are possible');break;caseRESULTS.GRANTED:
console.log('The permission is granted');break;caseRESULTS.BLOCKED:
console.log('The permission is denied and not requestable anymore');break;}});}functionrequestNotificationPermission(){requestNotifications(['alert','sound','badge']).then(({status})=>{switch(status){caseRESULTS.UNAVAILABLE:
console.log('This feature is not available (on this device / in this context)',);break;caseRESULTS.DENIED:
console.log('The permission has not been requested / is denied but requestable',);break;caseRESULTS.LIMITED:
console.log('The permission is limited: some actions are possible');break;caseRESULTS.GRANTED:
console.log('The permission is granted');break;caseRESULTS.BLOCKED:
console.log('The permission is denied and not requestable anymore');break;}});}functioncheckNotificationPermission2(){check(PERMISSIONS.ANDROID.POST_NOTIFICATIONS).then(result=>{switch(result){caseRESULTS.UNAVAILABLE:
console.log('This feature is not available (on this device / in this context)',);break;caseRESULTS.DENIED:
console.log('The permission has not been requested / is denied but requestable',);break;caseRESULTS.LIMITED:
console.log('The permission is limited: some actions are possible');break;caseRESULTS.GRANTED:
console.log('The permission is granted');break;caseRESULTS.BLOCKED:
console.log('The permission is denied and not requestable anymore');break;}});}functionrequestNotificationPermission2(){request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS).then(result=>{switch(result){caseRESULTS.UNAVAILABLE:
console.log('This feature is not available (on this device / in this context)',);break;caseRESULTS.DENIED:
console.log('The permission has not been requested / is denied but requestable',);break;caseRESULTS.LIMITED:
console.log('The permission is limited: some actions are possible');break;caseRESULTS.GRANTED:
console.log('The permission is granted');break;caseRESULTS.BLOCKED:
console.log('The permission is denied and not requestable anymore');break;}});}
The text was updated successfully, but these errors were encountered:
Hi 👋 This is expected, it cannot be known on Android before requested.
If you check the Android permission flow, you see that there's no way it returns blocked before calling request. That's also why the builtin module (PermissionsAndroid) return a boolean for check, and a status for request.
Before showing the screen that require the permission, check it
If it's granted, mount the screen that use it
If it's blocked, display a screen that explain that the user will have to go to settings to enable it (+ show a button that call openSettings) (will never ne visible on Android, but could be on iOS)
If it's denied, display a screen with a button to perform a request. After that, if it's granted -> mount the screen that use it. If it's blocked -> Display an alert or the blocked screen before encouraging going to the settings (using openSettings)
The UX is great on iOS, good enough on Android given the platform limitations
Bug summary
When I request notification permission and deny the dialog twice, then
check
returns that I can still request, butrequest
returns that user denied and cannot be requested again, so they conflict with each other.I tried to use
check
andrequest
apis andcheckNotifications
andrequestNotifications
apiLibrary version
4.0.0
Environment info
Steps to reproduce
request notification permissions twice and deny them, then check for permissions and you'll get that
DENIED
instead of expectedBLOCKED
Here is a video:
Screen.Recording.2023-12-05.at.10.11.45.PM.mov
Reproducible sample code
The text was updated successfully, but these errors were encountered: