iosswiftios-sharesheet

ios - format the information shared with share sheet


I am using the following code to present a share sheet:

let url = "https://somelink.com"
let image = "https://myserver/an_image.png"
let text = "Join now!"
    
let shareSheetVC = UIActivityViewController(activityItems: [image, url, text], applicationActivities: nil)
    
shareSheetVC.popoverPresentationController?.sourceView = sender
shareSheetVC.popoverPresentationController?.sourceRect = sender.frame
present(shareSheetVC, animated: true)

What I'd like is something like this:

enter image description here

However, when I share I just get

https://somelink.com https://myserver/an_image.png Join now!

How can I format this to accomplish something like the example?


Solution

  • This is the basic example to share Text, Image and URL using UIActivityViewController

     let text = "Join Now!"
     let image =  UIImage(named: "your_image")
     let myWebsite = URL(string: "https://somelink.com")
     let shareAll = [text , image! , myWebsite]
     let activityViewController = UIActivityViewController(activityItems: shareAll, applicationActivities: nil)
     activityViewController.popoverPresentationController?.sourceView = self.view 
     activityViewController.popoverPresentationController?.sourceRect = sender.frame
    
     self.present(activityViewController, animated: true, completion: nil)
    

    Hope you understand.