5

I want to use whatsapp in my app to send message to other phone. I have seen this public API for whatsapp on Github, here. But I dont find that API for iOS. So is that possible to use whatsapp in iOS app? And is that legal? And where can I find public API of whatsapp for iOS?

Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
Renish Dadhaniya
  • 10,642
  • 2
  • 31
  • 56

5 Answers5

11

yes, you can use the whatsapp for sending text/ images through you ios app. there are two ways to do so 1. URL scheme

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}
  1. UIDocumentInteraction see the link below http://www.whatsapp.com/faq/en/iphone/23559013
NSAnant
  • 816
  • 8
  • 18
2

Yes you can through :

  1. URL scheme
  2. UIDocumentInteraction

As @NSAnant mentioned

Just in case you are coding an hybrid app (Cordova,phonegap,etc) a simple anchor with the URL Scheme from Whatsapp FAQ will solve the issue (integrate WhatsApp into my app)

<a href="whatsapp://send?text=666isthenumberofthebeast" id="my_button" class="button_default button_color">Send Whatsapp Friendly Message</a>
d1jhoni1b
  • 7,497
  • 1
  • 51
  • 37
0

Is as simple as this. Hope it helps ;-)

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%20world"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    //WhatsApp is installed in your device and you can use it.
    [[UIApplication sharedApplication] openURL: whatsappURL];
} else {
    //WhatsApp is not installed or is not available
}
jobima
  • 5,790
  • 1
  • 20
  • 18
0

in iOS 9 : you need to Set key in info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>fbapi</string>
 <string>fbauth2</string>
 <string>fbshareextension</string>
 <string>fb-messenger-api</string>
 <string>twitter</string>
 <string>whatsapp</string>
 <string>wechat</string>
 <string>line</string>
 <string>instagram</string>
 <string>kakaotalk</string>
 <string>mqq</string>
 <string>vk</string>
 <string>comgooglemaps</string>
</array>

After set key, below code is working in iOS 9.

NSString * msg = @"mahesh";
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
} else {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}
Mahesh Cheliya
  • 1,334
  • 1
  • 16
  • 21
-2

No This is not legal. you cant use watsapp in your app.

Monish Bansal
  • 509
  • 3
  • 15