具有社交元数据的Firebase动态链接未在iMessage上显示图像(iOS消息)

时间:2020-04-26 19:37:07

标签: ios firebase-dynamic-links imessage

我在动态链接和社交元数据方面遇到问题。在Facebook上分享时似乎工作正常...图片已正确附加。但是,当我在iOS上使用“消息”共享...时,没有图像出现。只是Firebase文件夹徽标。

enter image description here

1 个答案:

答案 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
    }
}