在iOS中使用UIDocumentIntractionController将图像共享到WhatsApp
在iPhone应用程序开发中,是否可以使用UIDocumentIntractionController或API从iOS应用程序共享图像和文本到WhatsApp ?
您好,我发现如果您的应用程序创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
- Facebook和Twitter分享button停止工作
- UIActivityViewController与HTML
- WhatsApp共享不工作(相同的代码正在另一个项目中工作)
- UIActivityViewController与iOS中的UIDocumentInteractionController
- iOS – 分享图片+文字到WhatsApp?
- 通过WebRTCstream式传输屏幕截图,作为来自iOS的videostream
- iOS共享自定义对话框
- 社交活动表(如iOS 6)
- iOS 6共享消息,不像照片(UIActivityViewController和UIDocumentInteractionController)