Devner
Devner

Reputation: 7255

Ionic 4 + WhatsApp share - Get receiver / contact details after I share my message

I am using Ionic 4 + SocialSharing-PhoneGap-Plugin.

  1. After I share a message with my contact, how can I get back the contact's name/number and other info back in the promise, so that I can save it in the database?

I have the following code:

import { SocialSharing } from '@ionic-native/social-sharing/ngx';

constructor(private socialSharing: SocialSharing) { }

// Share message via WhatsApp
this.socialSharing.shareViaWhatsApp('Hi', null, null).then(() => {
  // How to get the contact's details here, with whom
 // I shared my message? Would like to get the name, number 
 // and all other contact info.

// Following Toast does not seem to trigger
this.toastService.presentToast('Successfully shared coupon on WhatsApp', 'success');
}).catch(() => {
  // Sharing via WhatsApp is not possible. How to trigger a toast here as well?
});
  1. How can I show a toast message immediately after return, so that I know that the message was shared successfully? As can be seen from the code, I have a toastService that shows the toast, but it never gets triggered. How can I trigger the toast after successfully sharing my message on WhatsApp, both in success & error cases?

Upvotes: 1

Views: 1315

Answers (1)

Alex Steinberg
Alex Steinberg

Reputation: 1466

To access contacts, you'll need a separate plugin like Contacts -- maybe get the contact first using that plugin and then use shareViaWhatsAppToPhone to share directly to that number.

The toast should work. From your example, it doesn't look like you've injected the ToastService into the class.

Upvotes: 0

Related Questions