null不是对象(评估'ImagePickerManager.showImagePicker')React Native Expo

时间:2019-12-24 15:34:36

标签: reactjs react-native

我的代码:

import ImagePicker from 'react-native-image-picker';

    const options = {
        title: 'Select Avatar',
        customButtons: [{ name: 'fb', title: 'Choose Photo from Facebook' }],
        storageOptions: {
          skipBackup: true,
          path: 'images',
        },
      };

    const [avatarSource, setAvatar] = useState(null);

    myFunc = async () => {
        ImagePicker.showImagePicker(options, (response) => {
            console.log('Response = ', response);
            if (response.didCancel) {
              console.log('User cancelled image picker');
            } else if (response.error) {
              console.log('ImagePicker Error: ', response.error);
            } else if (response.customButton) {
              console.log('User tapped custom button: ', response.customButton);
            } else {
              const source = { uri: response.uri };
              setAvatar(source);
            }
          });
    };

return():

<Button title="Image Picker" onPress={myFunc}/>

通过调用myFunc()会发生错误:

未处理的承诺拒绝:TypeError:空值不是对象(正在评估“ ImagePicker.showImagePicker”)

我试图做的事没有帮助:

  1. 运行react-native link react-native-image-picker并在调用后重建
  2. 运行react-native link
  3. 添加到 app.json :(我没有iod和android文件夹,并且已将这些字符串添加到app.json中)
    "android": {
      "permissions": [
        "CAMERA",
        "WRITE_EXTERNAL_STORAGE"
      ]
    }

    "ios": {
      "infoPlist": {
        "NSCameraUsageDescription": "This app uses the camera to scan barcodes on event tickets.",
        "NSPhotoLibraryUsageDescription": "This app would like access to your photo gallery",
        "NSPhotoLibraryAddUsageDescription": "This app would like to save photos to your photo gallery",
        "NSMicrophoneUsageDescription": "This app would like to use your microphone (for videos)"
      }
    }

有人可以帮忙吗?

0 个答案:

没有答案