React-Native-Expo Ask again for camera and camera roll permission in iOS?

Viewed 697

if the user denied on the first time the permission, how to ask them again?

i thought this should work but it doesn't. I don't know why? I figured out it's only on iOS.


(async () => {
  if (Platform.OS !== 'web') {
    console.log('Ask Permission')
    const libraryPermission = await ImagePicker.requestCameraRollPermissionsAsync();
    const cameraPermission = await ImagePicker.requestCameraPermissionsAsync();

    console.log("libraryPermission", libraryPermission)
    console.log("cameraPermission", cameraPermission)
    if (libraryPermission.status !== 'granted') {
      alert('Sorry, we need camera roll permissions to make this work!');
    }
    if (cameraPermission.status !== 'granted') {
      alert('Sorry, we need camera permissions to make this work!');
    }
  }
})();

export const takePhoto = async () => {
  const getCameraPermission = await ImagePicker.getCameraPermissionsAsync();
  console.log(getCameraPermission);
  if (!getCameraPermission.granted) {
    if (Platform.OS !== 'web') {
      const cameraPermission = await ImagePicker.requestCameraPermissionsAsync();
      if (cameraPermission.status !== 'granted') {
        alert('Sorry, we need camera roll permissions to make this work!');
      }
    }
  }
  const photo = await ImagePicker.launchCameraAsync({
    mediaTypes: ImagePicker.MediaTypeOptions.Images,
    allowsEditing: true,
    // aspect: [4, 3],
    quality: 1,
  });
  if (!photo.cancelled) {
    return photo;
  }
}

If a Click on the button takePhoto i get only this back:

cameraPermission Object {
  "canAskAgain": false,
  "expires": "never",
  "granted": false,
  "status": "denied",
}

And is there a way to ask for all permission once? So that the user don't get for each permission an popup.

thanks a lot.

0 Answers
Related