Bhavesh
Bhavesh

Reputation: 51

Ionic photo library does not load in iOS device

We need to load photos from camera or library(photo-gallery) and upload it. In Android device working fine but iOS has a below error: TypeError: Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"]) is not a function. (In 'Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"])(this, "getPicture", { "callbackOrder": "reverse" }, arguments)', 'Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"])' is an instance of Object)

Also, For more details see attached screenshot.

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

Upvotes: 0

Views: 201

Answers (1)

Jatin Devani
Jatin Devani

Reputation: 194

you need to add this line in your config file in ios platform

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

Upvotes: 1

Related Questions