Is this a bug report?
yes
yes
Environment
react-native: 0.45.1
Steps to Reproduce
use the react native api example for handling Android run time permissions,
https://facebook.github.io/react-native/docs/permissionsandroid.html#checkpermission
import{PermissionsAndroid}from'react-native';asyncfunctionrequestCameraPermission(){try{constgranted=awaitPermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA,{'title': 'Cool Photo App Camera Permission','message': 'Cool Photo App needs access to your camera '+'so you can take awesome pictures.'})if(granted===PermissionsAndroid.RESULTS.GRANTED){console.log("You can use the camera")}else{console.log("Camera permission denied")}}catch(err){console.warn(err)}}run the example method.
Expected Behavior
- run on Android >= 23. === will prompt the user for permission.
- run on Android < 23. === react-native will handle the cases and will print "You can use the camera" as if no
PermissionsAndroid was used. - run on iOS. === native ios permission behaviour as if
PermissionsAndroid was used.
Actual Behavior
- result as expected => prints "You can use the camera".
- result as if no permission granted - request returns true, not string 'granted'.
so result is "Camera permission denied". - throws an exception
index.ios.bundle:47286 TypeError: Cannotreadproperty'shouldShowRequestPermissionRationale'ofundefinedatPermissionsAndroid.request$(http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:53781:80)attryCatch(http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22558:40)atGenerator.invoke[as_invoke](http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22746:22)atGenerator.prototype.(anonymousfunction)[asnext](http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22583:21)attryCatch(http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22558:40)atinvoke(http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22616:20)at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22646:11attryCallTwo(http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:11879:5)atdoResolve(http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:12018:13)atnewPromise(http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:11900:3)
and no print at all.
i think all these cases should be handled by the api or specified in the example code.
the way to get it working in all three case is by modifying the example code to this:
asyncfunctionrequestCameraPermission(){try{constgranted=awaitPermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA,{'title': 'Cool Photo App Camera Permission','message': 'Cool Photo App needs access to your camera '+'so you can take awesome pictures.'})if(Platform.OS!=='android'||granted===true||granted===PermissionsAndroid.RESULTS.GRANTED){console.log("You can use the camera")}else{console.log("Camera permission denied")}}catch(err){console.warn(err)}}
Is this a bug report?
yes
Have you read the Contributing Guidelines?
yes
Environment
react-native: 0.45.1
Steps to Reproduce
use the react native api example for handling Android run time permissions,
https://facebook.github.io/react-native/docs/permissionsandroid.html#checkpermission
run the example method.
Expected Behavior
PermissionsAndroidwas used.PermissionsAndroidwas used.Actual Behavior
so result is "Camera permission denied".
and no print at all.
i think all these cases should be handled by the api or specified in the example code.
the way to get it working in all three case is by modifying the example code to this: