1

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?
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Devner
  • 6,825
  • 11
  • 63
  • 104

1 Answers1

0

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.

Alex Steinberg
  • 1,426
  • 13
  • 25
  • Thanks for your response. I checkout the Contacts plugin that you mentioned and it seems like the plugin is to `Access and manage Contacts on the device.` In my context, user will NOT create a new contact, rather, he will share a message with another WhatsApp user that he already added to his list. So the real task is to capture the details of the contact with whom the message was shared. No creation/deletion/update of any contacts is involved in the process. Any ideas on this? Showing Toast is not an issue, I just removed that code from the one that I posted for the sake of brevity. – Devner Oct 03 '19 at 10:08