Saturday, February 14, 2015

There are two method to share via whatsapp
  1. URL scheme
  2. Document Interaction API
If you want to go with URL Scheme
then here is example.

/**Just open whatsapp*/
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://app"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

/** Send Hello World! to any contact/group*/
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

/** Send message to selected contact*/
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://abid?/*Address Book ID*/"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

And if you want to go with Document Interaction API then check whatsapp documentation.

No comments:

Post a Comment