1

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?

4

2 回答 2

1

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.

于 2021-01-11T14:30:01.380 回答
0

Alternatively, you could approach this from a different angle and try to fix your webpage by adding:

<meta property="og:image" content="https://myserver/an_image.png">
<title>Join now!</title>

Those tags will be picked up by default from the UIActivityViewController.

于 2021-01-11T15:07:59.020 回答