Crash on sharing image in whatsapp ionic 3


#1

I have tried with camera plugin with my ionic app its work successfully. While i trying to share with social sharing it crashes and closed. Please find the code to rectify my error.

Note: If camera picture is not exceed in that base64image the share is working perfectly. If the picture exist its crashes so I think mistake may be related to that base64image I am not able to point the mistake let me help.

home.ts file

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';
import { SocialSharing } from '@ionic-native/social-sharing';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  public base64Image: string;
  
  constructor(public navCtrl: NavController, private camera: Camera, private socialSharing:SocialSharing) {

  }
opencamera()
{
  const options: CameraOptions = {
    quality: 100,
    destinationType: this.camera.DestinationType.DATA_URL,
    encodingType: this.camera.EncodingType.JPEG,
    mediaType: this.camera.MediaType.PICTURE
  }
  
  this.camera.getPicture(options).then((imageData) => {
   // imageData is either a base64 encoded string or a file URI
   // If it's base64:
    this.base64Image = 'data:image/jpeg;base64,' + imageData;
  }, (err) => {
   // Handle error
  });
  
  console.log('clicked camera button');


}
sharing()
{
  this.socialSharing.canShareViaEmail().then(() => {
    // Sharing via email is possible
    console.log('sharing is successfull');
  }).catch(() => {
    // Sharing via email is not possible
  });
  
  // Share via email
  this.socialSharing.shareViaWhatsAppToReceiver('98947XXXXX', 'checking sample', 'this.base64Image', null)
  .then(() => {
    // Success!
    console.log('shared');
  }).catch(() => {
    // Error!
  });
}

}

home.html file

<ion-header>
  <ion-navbar>
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Home</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <button ion-button icon-only (click)=opencamera() >
    <ion-icon name="camera">camera</ion-icon>
  </button>
  Latest Picture:
  <img [src]="base64Image" *ngIf="base64Image" />
  <button ion-button round (click)=sharing()>share</button>
  <button ion-button secondary menuToggle>Toggle Menu</button>
</ion-content>