离子照片库未在iOS设备中加载

时间:2019-03-15 09:28:53

标签: ionic-framework ionic3

我们需要从相机或图库(照片库)中加载照片并上传。 在Android设备上运行正常,但iOS出现以下错误: TypeError:对象( WEBPACK_IMPORTED_MODULE_1__ionic_native_core [“ cordova”])不是函数。 (在“对象( WEBPACK_IMPORTED_MODULE_1__ionic_native_core [ > [“ cordova”])'是Object的实例)

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

enter image description here 码: 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.');
      });
    }

1 个答案:

答案 0 :(得分:1)

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

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