swift - Share image via WhatsApp -


i have in app button share image via whatsapp , work. there strange thing appears in menu of uidocumentinteractioncontroller on devices. code:

        let urlwhats = "whatsapp://app"     if let urlstring = urlwhats.addingpercentencoding(withallowedcharacters:characterset.urlqueryallowed) {         if let whatsappurl = url(string: urlstring) {              if uiapplication.shared.canopenurl(whatsappurl url) {                  if let imagedata = uiimagejpegrepresentation(self.ivframedpicture.image!, 1.0) {                     let tempfile = url(fileurlwithpath: nshomedirectory()).appendingpathcomponent("/documents/whatsapptmp.wai")                     {                         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             }         }     } 

enter image description here if click on 1 whatsapp icon sends file doesn't open on iphones (android opens file image)

enter image description here

does can resolve problem? want 1 icon share image, that's it. thanks

simply use uiactivitycontroller sharing functionality instead of code.

example:

    if let image = self.ivframedpicture.image     {         let activityviewcontroller = uiactivityviewcontroller(activityitems: [image], applicationactivities: nil)         self.present(activityviewcontroller, animated: true, completion: nil)     } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -