ImagePicker Promise Rejects on First Attempt Though Permission.CAMERA Granted
See original GitHub issueSummary
Granting camera access then immediately using that access with ImagePicker
results in a promise rejection [Error: Missing camera or camera roll permission.]
.
Environment
Environment: OS: macOS High Sierra 10.13.4 Node: 8.2.1 Yarn: 1.2.1 npm: 5.3.0 Watchman: 4.9.0 Xcode: Xcode 9.3 Build version 9E145 Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed) expo: ^26.0.0 => 26.0.0 react: 16.3.0-alpha.1 => 16.3.0-alpha.1 react-native: https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz => 0.54.2
Diagnostics report: https://exp-xde-diagnostics.s3.amazonaws.com/geirman-9b12d065-1f0c-42c8-9884-9be91c7f5621.tar.gz
Expo Client
Steps to Reproduce
- Load the demo app below
- Tap “Pick from Camera” button
- Tap to authorize camera access
- RESULT: camera fails to launch, note the output of console.log
- Tap “Pick from Gallery” button
- Tap to authorize camera roll access
- RESULT: camera roll launches as expected, note output of console.log
- Tap “Pick from Camera” again
- RESULT: camera launches, note the output of console.log (everything is fine at this point)
Expected Behavior
For bullet 4 above, I expect camera launch and the following output after taking a photo…
camera granted
cameraRoll SUCCESS Object {
"cancelled": false,
"height": 2848,
"type": "image",
"uri": "file:///...54B7F932-9E42-443D-8B25-B41892A4C283.jpg",
"width": 4288,
}
For bullet 7 above, I expect camera roll to launch and the following output after taking a photo…
cameraRoll granted
cameraRoll SUCCESS Object {
"cancelled": false,
"height": 2848,
"type": "image",
"uri": "file:///.../54B7F932-9E42-443D-8B25-B41892A4C283.jpg",
"width": 4288,
}
Actual Behavior
Camera is not working correctly on first attempt. To spite being “granted” access, the promise rejects and the following is the output. Repeatedly tapping “Pick from Camera” will repeatedly result in a promise rejection. However, once I “Pick from Gallery”, then “Pick from Camera” will start working as expected.
camera granted
camera Object {
"error": [Error: Missing camera or camera roll permission.],
}
camera SUCCESS undefined
Reproducible Demo
https://snack.expo.io/@geirman/permissions-camera-camera-roll
import React, { Component } from 'react';
import { View, StyleSheet, Button } from 'react-native';
import { Constants, Permissions, ImagePicker } from 'expo';
export default class App extends Component {
pickFromGallery = async () => {
const permissions = Permissions.CAMERA_ROLL;
const { status } = await Permissions.askAsync(permissions);
console.log(permissions, status);
if(status === 'granted') {
let image = await ImagePicker.launchImageLibraryAsync({
mediaTypes: 'Images',
}).catch(error => console.log(permissions, { error }));
console.log(permissions, 'SUCCESS', image);
}
}
pickFromCamera = async () => {
const permissions = Permissions.CAMERA;
const { status } = await Permissions.askAsync(permissions);
console.log(permissions, status);
if(status === 'granted') {
let image = await ImagePicker.launchCameraAsync({
mediaTypes: 'Images',
}).catch(error => console.log(permissions, { error }));
console.log(permissions, 'SUCCESS', image);
}
}
render() {
return (
<View style={styles.container}>
<Button
title="Pick from Camera"
onPress={this.pickFromCamera}
/>
<Button
title="Pick from Gallery"
onPress={this.pickFromGallery}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'space-around',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
},
});
Issue Analytics
- State:
- Created 5 years ago
- Reactions:22
- Comments:52 (23 by maintainers)
Having the same issue using ImagePicker.launchImageLibraryAsync.
On my side it works locally on Expo but as soon as I publish to the Play Store it asks for permissions for both CAMERA and CAMERA_ROLL but the camera does not open.
Permissions:
Asking for both permissions in code: