是否可以在iPhone应用程序开发中使用UIDocumentIntractionController或API将iOS应用中的图像和文本共享到 WhatsApp ?
答案 0 :(得分:4)
答案 1 :(得分:0)
您好我发现如果您的应用程序创建照片,视频或音频笔记,并且您希望用户使用WhatsApp共享这些媒体,您可以使用文档交互API将您的媒体发送到WhatsApp联系人和群组。
答案 2 :(得分:0)
在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