回答
不,这是不可能的,whatsapp没有任何你可以使用的公共API。
请注意,当没有WhatsApp的API时,此答案对于2011是正确的。
现在有可与WhatsApp的交互的API:http://www.whatsapp.com/faq/en/iphone/23559013
Objective-C的调用打开其中一个网址如下:
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
现在是可能的。还没有尝试过。
最新release notes for whatsapp表明您可以通过共享扩展:
的WhatsApp接受下列类型的内容:
- 文本(UTI:public.plain文本)
- 照片(UTI :public.image)
- 视频(UTI:public.movie)
- 音频笔记和音乐文件(UTI:public.audio)
- PDF文档(UTI:com.adobe.pdf)
- 联系卡(UTI:public.vcard)
- 网页的URL(UTI:public.url)
它不可能只是打开应用程序,但不共享图像等:) :) – Rushabh
上面的链接是好的。这现在是可能的。这应该成为最好的答案。 –
上面的链接不允许在不显示菜单的情况下将媒体共享到WhatsApp。在使用WhatsApp之前,您必须始终显示文档控制器的菜单,这在屁股上很痛苦。 – user3344977
现在可以以这种方式:
发送文本 - 对象 -
NSString * msg = @"YOUR MSG";
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 {
// Cannot open whatsapp
}
发送文本 - 斯威夫特
let msg = "YOUR MSG"
let urlWhats = "whatsapp://send?text=\(msg)"
if let urlString = urlWhats.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.sharedApplication().canOpenURL(whatsappURL) {
UIApplication.sharedApplication().openURL(whatsappURL)
} else {
// Cannot open whatsapp
}
}
}
发送图像 - 的OBJ-C
- 在h文件
<UIDocumentInteractionControllerDelegate>
@property (retain) UIDocumentInteractionController * documentInteractionController;
- 英寸M档
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){
UIImage * iconImage = [UIImage imageNamed:@"YOUR IMAGE"];
NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];
[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
_documentInteractionController.UTI = @"net.whatsapp.image";
_documentInteractionController.delegate = self;
[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
发送图像 - 斯威夫特
let urlWhats = "whatsapp://app"
if let urlString = urlWhats.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.sharedApplication().canOpenURL(whatsappURL) {
if let image = UIImage(named: "image") {
if let imageData = UIImageJPEGRepresentation(image, 1.0) {
let tempFile = NSURL(fileURLWithPath: NSHomeDirectory()).URLByAppendingPathComponent("Documents/whatsAppTmp.wai")
do {
try imageData.writeToURL(tempFile, options: .DataWritingAtomic)
self.documentInteractionController = UIDocumentInteractionController(URL: tempFile)
self.documentInteractionController.UTI = "net.whatsapp.image"
self.documentInteractionController.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)
} catch {
print(error)
}
}
}
} else {
// Cannot open whatsapp
}
}
}
由于iOS版9的新的安全功能,则需要加上 的.plist文件这行:
<key>LSApplicationQueriesSchemes</key> <array> <string>whatsapp</string> </array>
更多形成关于网址sheme:https://developer.apple.com/videos/play/wwdc2015-703/
我没有找到一个单一的解决方案。 关于http://www.whatsapp.com/faq/en/iphone/23559013的更多信息
我做了一个小项目来帮助一些人。 https://github.com/salesawagner/SharingWhatsApp
是否有可能与android应用程序集成whatsapp – BeingMIAkashs
可以通过whatsapp将文本发送到特定的号码?意味着不需要从什么应用程序联系人列表中选择联系人? –
您需要将“ID地址簿”与联系人关联,只需添加参数“abid =
我在ShareKit中添加了一个WhatsApp Sharer。
是的,它是可能的:
NSMutableArray *arr = [[NSMutableArray alloc]init];
NSURL *URL = [NSURL fileURLWithPath:path];
NSString *textToShare = [NSString stringWithFormat:@"%@ \n",_model.title];
NSString *SchoolName= [[AppUtility sharedUtilityInstance]getAppConfigInfoByKey:@"SchoolName" SecondKeyorNil:Nil];
[arr addObject:textToShare];
[arr addObject:URL];
[arr addObject:_model.body];
[arr addObject:SchoolName];
TTOpenInAppActivity *openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:_parentController.view andRect:((UIButton *)sender).frame];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:arr applicationActivities:@[openInAppActivity]];
// Store reference to superview (UIActionSheet) to allow dismissal
openInAppActivity.superViewController = activityViewController;
// Show UIActivityViewController
[_parentController presentViewController:activityViewController animated:YES completion:NULL];
这是共享链接正确的代码,以什么应用程序的用户。
NSString * url = [NSString stringWithFormat:@"http://video...bla..bla.."];
url = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) url, NULL,CFSTR("!*'();:@&=+$,/?%#[]"),kCFStringEncodingUTF8));
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",url];
NSURL * whatsappURL = [NSURL URLWithString:urlWhats];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
// can not share with whats app
}
它的工作! –
斯威夫特3版瓦格纳销售的回答:
let urlWhats = "whatsapp://app"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) {
if let whatsappURL = URL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL) {
if let image = UIImage(named: "image") {
if let imageData = UIImageJPEGRepresentation(image, 1.0) {
let tempFile = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Documents/whatsAppTmp.wai")
do {
try imageData.write(to: tempFile!, options: .atomic)
self.documentIC = UIDocumentInteractionController(url: tempFile!)
self.documentIC.uti = "net.whatsapp.image"
self.documentIC.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
}
catch {
print(error)
}
}
}
} else {
// Cannot open whatsapp
}
}
}
NSString *shareText = @"http:www.google.com";
NSArray *objectsToShare = @[shareText];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
if (isIphone)
{
[self presentViewController:activityVC animated:YES completion:nil];
}
else {
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
你需要添加一些解释。你为什么认为这个代码有效?与以前的答案有什么不同? –
简单的代码和示例代码;-)
注: - 您只可以共享文本或图像,两者共享在whatsApp不工作从whatsApp方
/*
//Share text
NSString *textToShare = @"Enter your text to be shared";
NSArray *objectsToShare = @[textToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
*/
//Share Image
UIImage * image = [UIImage imageNamed:@"images"];
NSArray *objectsToShare = @[image];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
斯威夫特3版本发送文字:
func shareByWhatsapp(msg:String){
let urlWhats = "whatsapp://send?text=\(msg)"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL as URL) {
UIApplication.shared.openURL(whatsappURL as URL)
} else {
let alert = UIAlertController(title: NSLocalizedString("Whatsapp not found", comment: "Error message"),
message: NSLocalizedString("Could not found a installed app 'Whatsapp' to proceed with sharing.", comment: "Error description"),
preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("Ok", comment: "Alert button"), style: UIAlertActionStyle.default, handler:{ (UIAlertAction)in
}))
self.present(alert, animated: true, completion:nil)
// Cannot open whatsapp
}
}
}
}
另外,你需要在你的Info.plist
- 1. iOS分享图片和文字到WhatsApp
- 2. 通过whatsapp分享图像和文字
- 3. 通过whatsApp分享图片html5
- 4. 通过whatsapp分享图像ios 8
- 5. 通过iOS 9中的WhatsApp分享字符串+图像
- 6. 通过whatsapp分享
- 7. 分享mp3通过whatsapp,Android
- 8. 如何通过离子应用分享WhatsApp的图像
- 9. 分享图片到whatsapp Android 7.1.1
- 10. 如何通过Android中的WhatsApp共享图像+文本+网址?
- 11. WhatsApp分享在UIActivityViewController iOS中不工作?
- 12. 如何将我的应用程序中的图片分享给WhatsApp?
- 13. Android:通过intent.action_send分享图片和文字
- 14. 分享图像蚂蚁文本WhatsApp api iOS
- 15. 如何在iphone上分享whatsapp上的图片+文字说明(URL)?
- 16. 通过Android应用程序分享图片和标题到Instagram
- 17. 在ios的Instagram上分享带有图片的文字
- 18. 在whatsapp上分享谷歌静态地图图片
- 19. 以编程方式在IOS中的WhatsApp上分享图像和文本?
- 20. iOS - 是否有可能在程序中分享UIImage文本到iOS中的WhatsApp?
- 21. 在wordpress站点的whatsapp上分享图片
- 22. 如何通过iOS应用在Facebook上分享应用信息?
- 23. 分享链接使用whatsapp
- 24. 如何在facebooke上分享图像/ whatsapp/instagram fron ios xcode应用程序
- 25. 如何通过Android中的WhatsApp共享PDF和文本?
- 26. iOS:如何在社交网络上分享文字和图片?
- 27. 在IOS上的twitter上分享图片
- 28. 如何将图片和文字分享到Facebook应用程序
- 29. 我可以通过套接字分享地图片段吗?
- 30. 在twitter上分享图片和文字?
现在任何API该附加
whatsapp
到LSApplicationQueriesSchemes
,请帮帮我吧,我已经花费更多时间为 – SampathKumar不,仍然没有与iOS中的WhatsApp互动的API。 – rckoenes
你可以使用url方案与whatsapp应用程序交谈!请参阅@Wagner销售答案。 – JHNeves