i want to use Whatsapp share image in my Swift app using Xcode, the image will be downloaded from url , its working fine but the problem is that when i click on Whatsapp share button it doesn't open Whatsapp directly but open event where i can see all apps to share ,,, look this image
i want when user click on whatsapp it should open just whatsapp directly...
this is my code in button click
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) {
// Set your image's URL into here
let url = URL(string: "https://www.punjabidharti.com/wp-content/uploads/2022/11/1662625125251-600x600.jpg")!
data(from: url) { data, response, error in
guard let data = data, error == nil else { return }
DispatchQueue.main.async() { [self] in
let image = UIImage(data: data)
if let imageData = image?.jpegData(compressionQuality: 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 {
self.showToast(message: "Whatsapp Not Installed")
}
}
}