Search code examples
ioscordovacordova-pluginscordova-3

camera.getPicture is lagging too much of time in cordova ios from select gallery


I used cordova camera plugin for getting picture from the gallery in ios, for me the image gallery files not display faster its take too much of time to load... i used below codes only. its working, but its takes too much of time to load Photolibrary and one more thing was savetoPhotoAlbum is not working. But for android these two was work fine, its lag only on iOS

navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
      quality: 30,     
      allowEdit : false,
      encodingType: Camera.EncodingType.JPEG,
      destinationType: destinationType.DATA_URL,
      sourceType: pictureSource.PHOTOLIBRARY
    }); 

Please help me anyone ...


Solution

  • It is important giving "mediaType" value like "mediaType: this.camera.MediaType.PICTURE" in option.

      getImage(pictureSourceType, crop = true, quality = 50, allowEdit = true, saveToAlbum = true) {
        const options = {
          quality,
          allowEdit,
          destinationType: this.camera.DestinationType.FILE_URI,
          sourceType: pictureSourceType,
          encodingType: this.camera.EncodingType.JPEG,
          saveToPhotoAlbum: saveToAlbum,
          mediaType: this.camera.MediaType.PICTURE
        };
    
        // If set to crop, restricts the image to a square of 600 by 600
        if (crop) {
          options['targetWidth'] = 600;
          options['targetHeight'] = 600;
        }
    
        return this.camera.getPicture(options).then(imageData => {
          console.log("test 4");
          const base64Image = imageData;
          return base64Image;
        }, error => {
          console.log('CAMERA ERROR -> ' + JSON.stringify(error));
        });