Friday, February 3, 2023
HomeiOS Developmentios - The way to open Whatsapp to share picture from url...

ios – The way to open Whatsapp to share picture from url in Swift App?


i need to use Whatsapp share picture in my Swift app utilizing Xcode, the picture will likely be downloaded from url , its working tremendous however the issue is that when i click on on Whatsapp share button it would not open Whatsapp straight however open occasion the place i can see all apps to share ,,, look this picture

enter image description here

i need when person click on on whatsapp it ought to open simply whatsapp straight…

that is my code in button click on

 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 picture's URL into right here
                                       let url = URL(string: "https://www.punjabidharti.com/wp-content/uploads/2022/11/1662625125251-600x600.jpg")!
                                       knowledge(from: url) { knowledge, response, error in
                                           guard let knowledge = knowledge, error == nil else { return }
                                           DispatchQueue.predominant.async() { [self] in

                                               let picture = UIImage(knowledge: knowledge)
                                               if let imageData = picture?.jpegData(compressionQuality: 1.0) {
                                                   let tempFile = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Paperwork/whatsAppTmp.wai")
                                                   do {
                                                       attempt imageData.write(to: tempFile, choices: .atomic)
                                                       self.documentInteractionController = UIDocumentInteractionController(url: tempFile)
                                                       self.documentInteractionController.uti = "web.whatsapp.picture"
                                                       self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)

                                                   } catch {
                                                       print(error)
                                                   }
                                               }
                                           }
                                       }

                                   } else {
                                       self.showToast(message: "Whatsapp Not Put in")
                                   }
                               }
                           }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

18 + one =

Most Popular

Recent Comments