我在我的应用程序按钮中通过whatsapp共享图像,它确实有效 . 但是在某些设备上的UIDocumentInteractionController菜单中会出现一些奇怪的事情 . 这是代码:
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 imageData = UIImageJPEGRepresentation(self.ivFramedPicture.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.delegate = self
self.documentInteractionController.uti = "net.whatsapp.image"
self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
} catch {
print(error)
}
}
} else {
// Cannot open whatsapp
}
}
}
如果我点击1 whatsapp图标,它会发送一些无法在iPhone上打开的文件(Android打开该文件就像图像一样)
有没有人可以帮助解决这个问题?我只想要一个带共享图像的图标,就是这样 . 谢谢
2 回答
只需使用
UIActivityController
表示sharing
功能,而不是所有代码 .Example:
也许尝试使用UIActivityViewController