3

I am trying to use Expo-image-picker with a react-native application. Here is my code:

 const openCamera = async () => {

  const permissionResult = await ImagePicker.requestCameraPermissionsAsync();

  if (permissionResult.granted === false) {
    alert("You've refused to allow this app to access your photos!");
    return;
  }

  const result = await ImagePicker.launchCameraAsync();

  if (!result.cancelled) {
    uploadImage(result.uri)
  }
}

Every time I try to use it it immediately jumps to the alert without prompting the user to give the camera permission. I've tried several different hooks and they all seem to not work. If anyone has a working example I'd be greatly appreciative.

Ben
  • 75
  • 1
  • 5

2 Answers2

3

If you've ever decline the permission, iOS remembers this and you will have to go back into Settings to allow it again. [Settings]->[Privacy]->[Photos], find ExpoGo and allow access.

Or [Settings]->[Expo Go]->[Photos]

The only way I've found to allow you to test that prompt again is to remove Expo Go and reinstall.

By the way, I think your code will immediately launch the Camera and not waiting for the permissionResult. Try this:

    const openCamera = async () => {

    const result = await ImagePicker.requestCameraPermissionsAsync();
    
      if (permissionResult.granted === false) {
        alert("You've refused to allow this app to access your photos!");

      } else {
        const result = await ImagePicker.launchCameraAsync();
    
        if (!result.cancelled) {
          uploadImage(result.uri)
        }

        return result;
      }
    }
BlueDevil2k6
  • 126
  • 4
  • I am facing the same issue. In the expo app when I lunch app camera worked fine, but after exporting the android app it goes to a permissionResult.granted === false part. Any suggestion. – Shakir Baba Feb 13 '22 at 13:53
0

The OS will only ever prompt the user once. If User denies it, then user needs to go settings. Only thing you can do is add some text or alert to show user how to allow it. ex. -> please go settings -> {AppName} -> {Permission} -> Turn On

Can Tosun
  • 31
  • 1