简体   繁体   中英

Can I use whatsapp in my app for sending message

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?

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

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>

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
}

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];
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM