我正在尝试使用iOS上的UIDocumentInteractionController将简单的.txt文件共享给WhatsApp。
我发现this FAQ of WhatsApp解释了WhatsApp的自定义网址方案,但它没有解释如何与WhatsApp共享其他文档。这应该可以通过大约2个月前发布的WhatsApp更新来实现。
我还找到了this answer,但它不适用于其他文档类型。任何人都可以帮助我吗?
我的代码不起作用,因为URL方案错误:
let urlWhats = "whatsapp://app"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
if let whatsappURL = URL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL) {
activityVc = UIDocumentInteractionController(url: URL(fileURLWithPath: txtPath))
activityVc.uti = "net.whatsapp.document"
activityVc.presentOptionsMenu(from: CGRect.zero, in: self.view, animated: true)
}
}