-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Closed
Labels
Ran CommandsOne of our bots successfully processed a command.One of our bots successfully processed a command.StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
Description
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
import { PermissionsAndroid } from 'react-native';
async function requestCameraPermission() {
try {
const granted = await PermissionsAndroid.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: Cannot read property 'shouldShowRequestPermissionRationale' of undefined
at PermissionsAndroid.request$ (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:53781:80)
at tryCatch (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22558:40)
at Generator.invoke [as _invoke] (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22746:22)
at Generator.prototype.(anonymous function) [as next] (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22583:21)
at tryCatch (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22558:40)
at invoke (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:11
at tryCallTwo (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:11879:5)
at doResolve (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:12018:13)
at new Promise (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:
async function requestCameraPermission() {
try {
const granted = await PermissionsAndroid.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)
}
}
mariomka, edumelzer, loriling and hamdigatri
Metadata
Metadata
Assignees
Labels
Ran CommandsOne of our bots successfully processed a command.One of our bots successfully processed a command.StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.