【问题标题】:ios - format the information shared with share sheetios - 格式化与共享表共享的信息
【发布时间】:2021-04-16 11:46:04
【问题描述】:

我正在使用以下代码来展示分享表:

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)

我想要的是这样的:

但是,当我分享时,我会得到

https://somelink.com https://myserver/an_image.png 立即加入!

如何格式化它以完成类似于示例的操作?

【问题讨论】:

  • 您是否尝试过先下载图像然后将图像附加为文件?

标签: ios swift ios-sharesheet


【解决方案1】:

这是使用UIActivityViewController分享TextImageURL的基本示例

 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)

希望你能理解。

【讨论】:

  • 谢谢,这对我有帮助!
【解决方案2】:

或者,您可以从不同的角度解决此问题,并尝试通过添加以下内容来修复您的网页:

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

默认情况下,这些标签将从 UIActivityViewController 中获取。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 1970-01-01
    • 2022-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多