question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImagePicker Promise Rejects on First Attempt Though Permission.CAMERA Granted

See original GitHub issue

Summary

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

  1. Load the demo app below
  2. Tap “Pick from Camera” button
  3. Tap to authorize camera access
  4. RESULT: camera fails to launch, note the output of console.log
  5. Tap “Pick from Gallery” button
  6. Tap to authorize camera roll access
  7. RESULT: camera roll launches as expected, note output of console.log
  8. Tap “Pick from Camera” again
  9. 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:closed
  • Created 5 years ago
  • Reactions:22
  • Comments:52 (23 by maintainers)

github_iconTop GitHub Comments

7reactions
joduplessiscommented, Apr 30, 2018

Having the same issue using ImagePicker.launchImageLibraryAsync.

5reactions
dale-frenchcommented, Jun 7, 2018

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:

"permissions": [
        "ACCESS_COARSE_LOCATION",
        "ACCESS_FINE_LOCATION",
        "CAMERA",
        "READ_EXTERNAL_STORAGE",
        "READ_INTERNAL_STORAGE",
        "RECORD_AUDIO",
        "READ_PHONE_STATE",
        "READ_CONTACTS",
        "android.permission.CHANGE_CONFIGURATION",
        "com.google.android.c2dm.permission.RECEIVE",
        "android.permission.ACCESS_NETWORK_STATE"
]

Asking for both permissions in code:

const { cameraStatus } = await Permissions.askAsync(Permissions.CAMERA);
const { cameraRollStatus } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - ImagePicker Promise Rejects on First Attempt Though ...
Granting camera access then immediately using that access with ImagePicker results in a promise rejection [Error: Missing camera or camera roll permission.] ....
Read more >
Expo Image Picker: Unhandled promise rejection: TypeError ...
I am currently working on a small app and I want load images from camera roll into the app. I' ...
Read more >
ImagePicker - Expo Documentation
Asks the user to grant permissions for accessing camera. This does nothing on web because the browser camera is not used. Returns.
Read more >
Uploading pictures to Firebase in React Native - Marcusoft.net
'granted') { alert('Sorry, we need camera roll permissions to make ... new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); ...
Read more >
Expo Image Picker: Unhandled Promise Rejection: Typeerror
ImagePicker Promise Rejects on First Attempt Though Permission.CAMERA Granted. .possible Unhandled Promise Rejection id:1 TypeError:Network request failed ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found