我能在我的应用中使用WhatsApp发送消息吗?

5

我想在我的应用程序中使用 WhatsApp 给其他手机发送消息。我在 GitHub 上看到了这个公共 API,在这里。但是我没有找到适用于 iOS 的该 API。因此,是否可能在 iOS 应用程序中使用 WhatsApp?是否合法?在哪里可以找到适用于 iOS 的 WhatsApp 公共 API?

5个回答

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

2

您可以通过以下方式实现:

  1. URL方案
  2. UIDocumentInteraction

正如@NSAnant所提到的那样,如果您正在编写混合应用程序(Cordova,phonegap等),则使用Whatsapp FAQ中的URL Scheme创建一个简单的锚点即可解决问题(将WhatsApp集成到我的应用程序中)。

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

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

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
}

-2

不行,这是不合法的。你不能在你的应用程序中使用WhatsApp。


但是在那个 GitHub 的链接中有 PHP 的公共 API。 - Renish Dadhaniya
不,该API并非公开的,Github上的代码是反向工程而来的。因此,你可以合法地查看其工作原理,但在你的应用程序中使用是违法的。 - rckoenes
苹果肯定会拒绝该应用程序。 - Monish Bansal
请查看以下链接:http://www.whatsapp.com/faq/en/iphone/23559013 - Sunil Targe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接