1
votes

Explanation -: 1. I am working on ionic project where I am trying to share link via whatsapp

  1. I have used shareViaWhatsApp(message, image, url) function from https://ionicframework.com/docs/native/social-sharing/

  2. I have followed all the steps looking into the doc given by Ionic

  3. But PROBLEM is -:

    When I am trying to share link via whatsapp window opens but it gives a message sharing failed please try again then whatsapp window closed , and sharing failed

I am putting code below -:

  shareViaWhatsapp(){
    console.log('invitewhatsapp');
    let message = 'Abcd';
    //let image = 'sdfgbdh.jpg';
    let url = "www.facebook.com";
    this.socialShare
      .shareViaWhatsApp(message,url,null)
      .then(() => {
        console.log('success');
      })
      .catch(() => {
        console.log('Error');
      });
  }

html ->

<button ion-fab (click)="shareViaWhatsapp()"><ion-icon name="logo-whatsapp"></ion-icon></button>
1

1 Answers

2
votes

The second parameter is for the image and the third is for URL. Replace your code with this one:

this.socialShare
  .shareViaWhatsApp("Abcd",undefined,"www.facebook.com")
  .then(() => {
    console.log('success');
  })
  .catch(() => {
    console.log('Error');
  });

More info about share via whatsapp