首页 > 解决方案 > Ionic 照片库无法在 iOS 设备中加载

问题描述

我们需要从相机或图书馆(照片库)加载照片并上传。在 Android 设备上工作正常,但 iOS 出现以下错误:TypeError: Object( WEBPACK_IMPORTED_MODULE_1__ionic_native_core ["cordova"]) is not a function。(在 'Object( WEBPACK_IMPORTED_MODULE_1__ionic_native_core ["cordova"])(this, "getPicture", { "callbackOrder": "reverse" }, arguments)', 'Object( WEBPACK_IMPORTED_MODULE_1__ionic_native_core ["cordova"])' 是 Object 的一个实例)

此外,有关更多详细信息,请参阅随附的屏幕截图。

在此处输入图像描述 代码:if(sourceType=='library') {

        const Liboptions: CameraOptions = {
          quality: 100,
          destinationType: this.camera.DestinationType.FILE_URI,
          encodingType: this.camera.EncodingType.JPEG,
          mediaType: this.camera.MediaType.PICTURE,
          sourceType:0,
          saveToPhotoAlbum:true,
          targetWidth:1024,
          targetHeight:720,
          allowEdit:true
        }

        this.camera.getPicture(Liboptions).then((imagePath) => {
        // Special handling for Android library

          var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
          var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
          this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
      }, (err) => {
        this.presentToast('Error while selecting image.');
      });

    } else {

        const CamOptions: CameraOptions = {
          quality: 100,
          destinationType: this.camera.DestinationType.FILE_URI,
          encodingType: this.camera.EncodingType.JPEG,
          mediaType: this.camera.MediaType.PICTURE,
          sourceType: this.camera.PictureSourceType.CAMERA,
          targetWidth:1024,
          targetHeight:720
        }
        //options.popoverOptions = CameraPopoverOption; options.correctOrientation = true;
        this.camera.getPicture(CamOptions).then((imagePath) => {
        // Special handling for Android library

          var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
          var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
          this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
      }, (err) => {
        this.presentToast('Error while selecting image.');
      });
    }

标签: ionic-frameworkionic3

解决方案


您需要在 ios 平台的配置文件中添加此行

<config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
 <string>You can take photos</string>
</config-file>

推荐阅读