在iOS中使用UIDocumentIntractionController将图像共享到WhatsApp

在iPhone应用程序开发中,是否可以使用UIDocumentIntractionController或API从iOS应用程序共享图像和文本到WhatsApp

请看一下这个。

http://www.whatsapp.com/faq/en/iphone/23559013

希望对你有帮助。

祝一切顺利。

您好,我发现如果您的应用程序创build照片,video或audio笔记,并且您希望您的用户使用WhatsApp共享这些媒体,则可以使用文档交互API将媒体发送到WhatsApp联系人和组。

你可以参考这个链接: http : //www.whatsapp.com/faq/en/iphone/23559013

在Swift 3中使用这个代码

@IBAction func whatsappShareWithImages(_ sender: AnyObject) { let urlWhats = "whatsapp://app" if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed) { if let whatsappURL = URL(string: urlString) { if UIApplication.shared.canOpenURL(whatsappURL as URL) { if let image = UIImage(named: "whatsappIcon") { if let imageData = UIImageJPEGRepresentation(image, 1.0) { let tempFile = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Documents/whatsAppTmp.wai") do { try imageData.write(to: tempFile, options: .atomic) self.documentInteractionController = UIDocumentInteractionController(url: tempFile) self.documentInteractionController.uti = "net.whatsapp.image" self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true) } catch { print(error) } } } } else { // Cannot open whatsapp } } } } 

在您的应用程序中添加此代码“plist”

  <key>LSApplicationQueriesSchemes</key> <array> <string>whatsapp</string> </array> 

您也可以参考小应用程序以供参考: https : //github.com/nithinbemitk/iOS-Whatsapp-Share