首页 > 解决方案 > 打开相机时应用程序崩溃

问题描述

我在我的应用程序中使用https://github.com/ivpusic/react-native-image-crop-picker,当相机打开时我可以拍照,但是当我想选择它时,应用程序崩溃了,有时它崩溃了一次相机已打开,但是当我使用调试模式而不是在 android 上运行时,它在所有情况下都运行良好。

当我从 xcode 运行项目时工作正常,但不适用于 react-native run-ios --device "myDeviceName"

也有更高版本的 ios 像 13 它运行良好

我调用打开相机时的组件:

ImagePicker.openCamera({
          cropping: true,
          width: 500,
          height: 500,
          includeExif: true,
          includeBase64: true,
          mediaType:"photo"
        })
          .then(image => {
            this.setState({
              cameraOpened: false
            });
            this.props.navigation.navigate("Preview", {
              picture: image,
              type: this.type,
              state: this.props.navigation.state,
              userId: this.userId
            });
          })
          .catch(e => {
            console.log(e);
            this.setState({
              cameraOpened: false
            });
            this.props.navigation.goBack();
          });
      }

预览.js:

ImageEditor.cropImage(
          this.picture.path,
          {
            offset: { x: 0, y: 0 },
            size: { width: 500, height: 500 },
            displaySize: { width: 500, height: 500 }
          },
          res => {
            // Change it to res
            this._uploadPicture(this.picture.path, response => {
              if (response.status == 200) {
                this.props.savePicture(this.picture);
                this.setState(
                  {
                    loading: false
                  },
                  () => {
                    this.navigation.goBack(key);
                  }
                );
              } else {
                alert(response);
              }
            });
          },
          err => {
            this.setState({
              loading: false
            });
            alert(err);
          }
        );

任何想法 ?谢谢

标签: iosreact-native

解决方案


稍后,但对于期货搜索者:

我遇到了同样的问题,即使在 Info.plist 中添加了 NSPhotoLibraryAddUsageDescription, NSPhotoLibraryUsageDescription, NSMicrophoneUsageDescription, NSCameraUsageDescription,我还是收到了来自 Apple Store connect 的电子邮件,内容是“Info.plist 中缺少目的字符串”。

这次我错过了“NSAppleMusicUsageDescription”。我不确定为什么我需要这个属性,因为我的应用程序中没有音乐,但它对我有用。


推荐阅读