ImagePicker表示我没有相机胶卷许可权,但是我找不到任何有关此文件的文档

时间:2019-05-15 18:59:38

标签: react-native expo

我正在应用程序中制作一个上传屏幕,我想我已经完成了大部分操作,但是它警告我缺少相机胶卷权限。我需要一些解决此问题的帮助。

我一直在网上寻找文档。

这是文档

import { View, Dimensions, StyleSheet, Button } from 'react-native';
import { Icon } from 'native-base';
import { ImagePicker } from 'expo';


var { width, height } = Dimensions.get('window');
class UploadTab extends Component {
  static navigationOptions = {
    tabBarIcon: ({ tintColor }) => (
      <Icon name="ios-add-circle" style={{ color: tintColor }} />
    )
  };
  state = {
    image: null
  };

  _handleChoosePhoto = async () => {
    let result = await ImagePicker.launchImageLibraryAsync({
      allowsEditing: true,
      aspect: [4, 3]
    });
    console.log(result);
    if (!result.cancelled) {
      this.setState({ image: result.uri });
    }
    const options = {};
    ImagePicker.launchImageLibrary(options, response => {
      console.log('response', response);
    });
  };
  render() {
    let { image } = this.state;

    return (
      <View
        style={{
          flex: 1,
          alignItems: 'center',
          justifyContent: 'center',
          backgroundColor: '#1f1f1f',
          width: width,
          height: height
        }}
      >
        <Button title="Choose Photo" onPress={this._handleChoosePhoto} />
        {image && (
          <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />
        )}
      </View>
    );
  }
}
export default UploadTab;

我需要按钮来打开相机胶卷,以便选择要上传的内容。

警告(黄色) 可能的未处理的承诺拒绝(编号:6): 错误:缺少相机胶卷许可。 ...

1 个答案:

答案 0 :(得分:2)

在文档中:https://docs.expo.io/versions/latest/sdk/imagepicker/#api

  

显示系统UI,以从手机的资料库中选择图像或视频。仅在iOS上需要Permissions.CAMERA_ROLL

在以下位置:https://docs.expo.io/versions/latest/sdk/permissions/#permissionsaskasynctypes

async function getLocationAsync() {
  const { Location, Permissions } = Expo;
  // permissions returns only for location permissions on iOS and under certain conditions, see Permissions.LOCATION
  const { status, permissions } = await Permissions.askAsync(Permissions.LOCATION);
  if (status === 'granted') {
    return Location.getCurrentPositionAsync({enableHighAccuracy: true});
  } else {
    throw new Error('Location permission not granted');
  }
}

使用您需要的权限交换位置