IOS Standalone App - Camera & Camera Roll Not Working

Well, I need to use the camera & camera roll in my app, so the user can load profile pictures. I followed the expo examples & make some research, but I can’t found why it doesn’t work in IOS standalone app.

A fresh install of the app ask for the permissions and, after accepted them, you can access the camera OR the camera roll, but only once. The second time nothing happens, nor errors nor nothing.
For example: user accepts the permissions, open the camera, close it or take a picture, try to access again the camera or the camera roll and nothing happens :disappointed:

Locally it works :man_shrugging:

I leave an example code:

  • Get the permissions.
  • Check if both are granted
  • If not, ask for the permissions
  askPermissionsAsync = async () => {
    const { status, permissions } = await Permissions.getAsync(Permissions.CAMERA, Permissions.CAMERA_ROLL);

    if (status !== 'granted') {
      if (permissions[Permissions.CAMERA].status !== 'granted') {
        const cameraPermission = await Permissions.askAsync(Permissions.CAMERA);

        if (cameraPermission.status !== 'granted') {
          this.setState({
            errorMessage: 'Permission to access the camera was denied',
          });
        }
      }

      if (permissions[Permissions.CAMERA_ROLL].status !== 'granted') {
        const cameraRollPermission = await Permissions.askAsync(Permissions.CAMERA_ROLL);

        if (cameraRollPermission.status !== 'granted') {
          this.setState({
            errorMessage: 'Permission to access the camera roll was denied',
          });
        }
      }
    }
  }

  pickImage = async () => {
    await this.askPermissionsAsync();
    const result = await ImagePicker.launchImageLibraryAsync();
    !result.cancelled && this.handleImagePicked(result.uri);
  }

  takePhoto = async () => {
    await this.askPermissionsAsync();
    const result = await ImagePicker.launchCameraAsync();
    !result.cancelled && this.handleImagePicked(result.uri);
  }

I can share a video of the problem in the standalone app, if needed.
Thanks in advance!

Hey @matias.calvo,

What SDK version is your project running?

Cheers,
Adam

1 Like

Ouch! I forgot to add that in the original post. Sorry.

app.json:

“sdkVersion”: “32.0.0”

package.json:

“expo”: “^32.0.0”,
“react-native”: “https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz”,

Today I found this “fix”:

  pickImage = async () => {
    await this.askPermissionsAsync();

    setTimeout(async () => {
      const result = await ImagePicker.launchImageLibraryAsync();
      !result.cancelled && this.handleImagePicked(result.uri);
    }, 1200);
  }

  takePhoto = async () => {
    await this.askPermissionsAsync();

    setTimeout(async () => {
      const result = await ImagePicker.launchCameraAsync();
      !result.cancelled && this.handleImagePicked(result.uri);
    }, 1200);
  }

For some weird reason, with the setTimeout, the camera roll and the camera opens without problem.
I tried this approach because after I put a breakpoint both options opens, so it occurred to me that it could be a timing problem.

Is not a good or desired solution, but will work until I found something better.

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