答案 0 :(得分:1)
我遇到了完全相同的问题,并且找到了一种通过创建LPLinkMetadata中的LinkPresentation来在iMessage中显示预览图像的方法。即使它不能解决核心问题,它似乎也能正常工作。
基本上,我下载了该图像以首先在预览中显示,并基于该图像创建LPLinkMetadata。
let image = UIImage(data: data)! //Image to show in preview
let metadata = LPLinkMetadata()
metadata.imageProvider = NSItemProvider(object: image)
metadata.originalURL = url //dynamic links
metadata.title = "Holland Bloorview Kids Rehabilitation Hospital on Flixxaid"
let metadataItemSource = LinkPresentationItemSource(metaData: metadata)
let activity = UIActivityViewController(activityItems: [metadataItemSource], applicationActivities: [])
self.present(activity, animated: true)
并且LinkPresentaionItemSource来自this blog。
class LinkPresentationItemSource: NSObject, UIActivityItemSource {
var linkMetaData = LPLinkMetadata()
//Prepare data to share
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
return linkMetaData
}
//Placeholder for real data, we don't care in this example so just return a simple string
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return "Placeholder"
}
/// Return the data will be shared
/// - Parameters:
/// - activityType: Ex: mail, message, airdrop, etc..
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
return linkMetaData.originalURL
}
init(metaData: LPLinkMetadata) {
self.linkMetaData = metaData
}
}