Search code examples
cordovaionic-frameworkcapacitorionic5socialsharing-plugin

Ionic 5 socialSharing.shareViaWhatsAppToPhone not attaching image


I am using Social Sharing plugin in Ionic 5 and having issues in sharing image via whatsApp. If I share image via "shareViewWhatsApp" then everything works fine. After selecting contact it shows image that I am sharing.

But if I use "shareViaWhatsAppToPhone" or "shareViaWhatsAppToReceiver" to share image whatsapp contact directly then it seems to ignore the image and only shares text message.

var node = document.getElementById('body') ;
domtoimage.toPng(node) 
    .then((dataUrl) => {
      this.socialSharing.shareViaWhatsAppToPhone('+61xxxxxxxxx','share toPhone', dataUrl,null).then((res) => {
        console.log('image shared with whatsapp');
      }).catch((e) => {
        console.error('social share, something went wrong!', e);
      });
    })
    .catch((error) => {
        console.error('oops, something went wrong!', error);
    });

"domtoimage.toPng()" is just a plug in to convert Dom node to image. Ref: https://github.com/tsayen/dom-to-image

dataUrl looks like: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..."

Any help would be much appriciated.

Thanks


Solution

  • Hi i had the same issue earlier later i found out in this documentation(https://www.npmjs.com/package/cordova-plugin-x-socialsharing) it is clearly mentions files are ignored in android while sending directly to number enter image description here

    so u can try something like

    this.socialSharing.shareViaWhatsApp('share toPhone', dataUrl,null).then((res) => {
          console.log('image shared with whatsapp');
        }).catch((e) => {
          console.error('social share, something went wrong!', e);
        });
      })
      .catch((error) => {
          console.error('oops, something went wrong!', error);
      });