直接将图像共享到WhatsApp而不在iOS上运行
为了找到一种直接向WhatsApp共享图像的方法,我已经仔细研究了几个SO问题(例如,or)。他们似乎都遵循的指示,所以我最终采用了这种方法:直接将图像共享到WhatsApp而不在iOS上运行,ios,swift,whatsapp,Ios,Swift,Whatsapp,为了找到一种直接向WhatsApp共享图像的方法,我已经仔细研究了几个SO问题(例如,or)。他们似乎都遵循的指示,所以我最终采用了这种方法: extension WhatsAppInviter { func shareImageViaWhatsapp(image: UIImage, onView: UIView) { let urlWhats = "whatsapp://app" if let urlString = urlWhats
extension WhatsAppInviter {
func shareImageViaWhatsapp(image: UIImage, onView: UIView) {
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) {
guard let imageData = image.pngData() else { debugPrint("Cannot convert image to data!")
return }
let tempFile = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Documents/image.wai")
do {
try imageData.write(to: tempFile, options: .atomic)
documentInteractionController = UIDocumentInteractionController(url: tempFile)
documentInteractionController?.uti = "net.whatsapp.image"
documentInteractionController?.presentOpenInMenu(from: CGRect.zero, in: onView, animated: true)
} catch {
UIAlertController.presentAlertWith(title: "Error", message: "There was an error while processing.", actions: [UIAlertAction(title: "OK", style: .default, handler: nil)])
return
}
} else {
UIAlertController.presentAlertWith(title: "Error", message: "Cannot open Whatsapp, make sure Whatsapp is installed on your device.", actions: [UIAlertAction(title: "OK", style: .default, handler: nil)])
}
}
}
}
}
《公约》明确规定:
或者,如果您希望在应用程序列表中仅显示WhatsApp(而不是WhatsApp加上任何其他符合/*-标准的公共应用程序),您可以指定上述类型之一的文件,该文件以WhatsApp独有的扩展名保存:
images-«.wai»类型为net.whatsapp.image
视频-«.wam»类型为net.whatsapp.movie
音频文件-«.waa»,其类型为net.whatsapp.audio
触发后,WhatsApp将立即向用户显示联系人/组选择器屏幕。媒体将自动发送到选定的联系人/组
但是,在执行这段代码时,我一直在获取文档交互控制器,正如您在这里看到的:
我是做错了什么,还是iOS 13有什么变化?我怎样才能跳过这个菜单,或者至少只在那里显示WhatsApp?你找到菜单了吗solution@AqibZareen不,不是雪人猜测指定独占uri和扩展在最近的ios 13和14中不再起作用。我尝试了com.instagram.exclusivegram(带有*.igo)来分享给instagram,但它也不起作用。