React-Native-Expo再次询问iOS中的相机和相机胶卷许可吗?

时间:2020-09-29 12:02:59

标签: react-native permissions camera expo

如果用户首次拒绝该许可,如何再次询问他们?

我认为这应该可以,但是不能。不知道为什么我发现它仅在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;
  }
}

如果单击takePhoto按钮,我只会得到以下信息:

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

是否有一种方法可以一次请求所有许可?这样用户就不会为每个权限都弹出一个窗口。

非常感谢。

0 个答案:

没有答案
相关问题