Hi, I’m currently working in React Native trying to open the camera to let the user add an image. I want to do this with the ImagePicker library and the function launchCameraAsync. The problem is that, when I try to execute the function
What’s weird is that, just before calling launchCameraAsync, i call requestCameraPermissionsAsyncand it returns granted = true, meaning that the permissions to use the camera are provided.
This is my code:
const askPermissionsAsync = async () => {
await Permissions.askAsync(Permissions.CAMERA);
await Permissions.askAsync(Permissions.CAMERA_ROLL);
};
const pickFromGallery = async () => {
await askPermissionsAsync();
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (status === 'granted') {
let data = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [1, 1.5],
quality: 0.5,
base64: true
});
setImage1(data);
} else {
Alert.alert('Permission denied');
}
}
const pickFromCamera = async () => {
await askPermissionsAsync();
const { status } = await ImagePicker.requestCameraPermissionsAsync()
if (status === 'granted') {
let data = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [1, 1.5],
quality: 0.5,
base64: true,
cameraType: ImagePicker.CameraType.back
});
setImage1(data);
} else {
Alert.alert('Permission denied');
}
}
app.json configuration