我可以在我的应用程序中使用whatsapp发送消息

时间:2013-03-07 08:07:59

标签: iphone ios whatsapp

我想在我的应用中使用whatsapp将消息发送到其他手机。我在Github上看到了这个用于whatsapp的公共API,here。但我没有找到适用于iOS的API。那么可以在iOS应用程序中使用whatsapp吗?这合法吗?我在哪里可以找到适用于iOS的whatsapp的公共API?

5 个答案:

答案 0 :(得分:11)

是的,您可以使用whatsapp通过ios应用程序发送文本/图像。 有两种方法可以做到这一点  1. URL方案

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}
  1. UIDocumentInteraction 请参阅下面的链接 http://www.whatsapp.com/faq/en/iphone/23559013

答案 1 :(得分:2)

是的,你可以通过:

  1. 网址计划
  2. UIDocumentInteraction
  3. 正如@NSAnant所说

    如果您正在编写混合应用程序(Cordova,phonegap等),使用Whatsapp常见问题解答中的URL方案的简单锚点将解决问题(integrate WhatsApp into my app)

    <a href="whatsapp://send?text=666isthenumberofthebeast" id="my_button" class="button_default button_color">Send Whatsapp Friendly Message</a>
    

答案 2 :(得分:0)

就像这一样简单。希望它有所帮助; - )

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
}

答案 3 :(得分:0)

iOS 9 中的

:您需要在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>

设置密钥后,下面的代码在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];
}

答案 4 :(得分:-2)

否这不合法。你可以在你的应用程序中使用whatsapp。