IOS ImagePicker doesn't open camera

Hello all!

Although for both CAMERA and CAMERA_ROLL status returns granted, it doesn’t open the camera on IOS, iPad.

I’m using SDK 33.

The relevant part of the code is below. And I have two buttons, one for enableCameraRollPicker and the other one for takeImage function.

Thanks in advance!

import Constants from 'expo-constants';
import * as Permissions from 'expo-permissions';
import * as ImagePicker from 'expo-image-picker';

getPermissionAsync = async () => {
    if (Constants.platform.ios) {

      const { status: cameraRollStatus } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
      if (cameraRollStatus !== 'granted') {
          alert('Sorry, we need camera roll permissions to make this work!');
      }

      const { status: cameraStatus } = await Permissions.askAsync(Permissions.CAMERA);
      if (cameraStatus !== 'granted') {
          alert('Sorry, we need camera permissions to make this work!');
      }
    }
  }

enableCameraRollPicker = async () => {
    const { ApplicationState } = this.props;

    await this.getPermissionAsync();

    ApplicationState.setOptionsModalActive(false)
    ApplicationState.setCameraRollPickerActive(true);
  }

  takeImage = async () => {
    const { ApplicationState } = this.props;

    await this.getPermissionAsync();

    ApplicationState.setOptionsModalActive(false);
    const result = await ImagePicker.launchCameraAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.All,
      exif: true
    });
    if (!result.cancelled) {
      console.log(result);
      ApplicationState.setPhotosToPost([{
        uri: result.uri,
        description: null,
      }]);
      this.enableDescriptionModal();
    }
  }


Hey there! This snack seems to work fine (SDK 33), so I suggest taking a look at what’s different between the two to find out why your Camera won’t open (make sure to test on a real device)

1 Like

Thank you for your reply. However, CameraRoll also works fine for me. My problem is with using camera and taking a photo.

Sorry, i used a different snack as a base and didn’t change the name or the button, but if you click the Pick an image from camera roll button, it’ll launch the camera! You can see exactly what it’s doing in the code

I changed my code accordingly, moved this.getPermissionAsync() into componentDidMount() from buttons’ functions. Yet, the problem is both the snack and the changed code do not work for ios for me.

The snack I linked doesn’t work? Then it’s probably specific to your device. Make sure it’s not a simulator (can’t open camera on simulators)

1 Like

Oh camera doesn’t work with simulator, I’m sorry. Now I tried with an iPad and it’s working. Thank you very much for your help.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.