5

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

4

5 回答 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
于 2014-02-21T12:29:04.497 回答
2

是的,您可以通过:

  1. 网址方案
  2. UIDocumentInteraction

正如@NSAnant 提到的

万一您正在编写混合应用程序(Cordova、phonegap 等),使用 Whatsapp FAQ 中的 URL 方案的简单锚点将解决问题(将 WhatsApp 集成到我的应用程序中)

<a href="whatsapp://send?text=666isthenumberofthebeast" id="my_button" class="button_default button_color">Send Whatsapp Friendly Message</a>
于 2014-08-09T02:28:46.913 回答
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
}
于 2014-07-18T07:46:51.927 回答
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];
}
于 2016-01-30T10:14:37.773 回答
-2

不 这不合法。你不能在你的应用程序中使用 watsapp。

于 2013-03-07T08:10:46.623 回答