回答
不,這是不可能的,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