【问题标题】:Ionic photo library does not load in iOS deviceIonic 照片库无法在 iOS 设备中加载
【发布时间】:2019-03-15 21:33:30
【问题描述】:

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

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

enter image description here 代码: if(sourceType=='库') {

        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-framework ionic3


    【解决方案1】:

    你需要在 ios 平台的配置文件中添加这一行

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多