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 } } }
if click on 1 whatsapp icon sends file doesn't open on iphones (android opens file image)
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
Post a Comment