问题描述
我正在尝试在不使用 Twitter Kit 库的情况下将 iOS 应用中的图像和标题分享到 Twitter。理想情况下,它应该与我附加在这篇文章中的 Spotify 共享完全一样。对此有什么想法吗?
我浏览了 Twitter 文档,但没有看到太多关于此主题的内容。
我也尝试过使用 Apple 的 SLComposeViewController,但问题是图像在 Twitter 上显示时显示为 URL 而不是图像:
if let vc = SLComposeViewController(forServiceType: SLServiceTypeTwitter) {
vc.setinitialText("some caption")
vc.add(UIImage(named: "my_image",in: InternalConstants.bundle,compatibleWith: nil)!)
vc.modalPresentationStyle = .formSheet
nc.present(vc,animated: true)
}
请不要将此问题标记为重复,除非解决方案提供即时深层链接,如所附 gif 所示。
谢谢!
解决方法
Spotify 不分享图片和标题!相反,它共享一个指向站点的链接,该链接包含正确的元数据以显示 image
、title
、description
等。您可以通过阅读有关Open Graph Protocol 和丰富链接
总而言之,目标页面应在标题中包含以下内容:
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="https://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="https://ia.media-imdb.com/images/rock.jpg" />
示例取自 ogp.me
在 Tweeter 上预览示例
请注意记住一些社交媒体和平台支持不同的元!确保在所有目标平台(WhatsApp、Telegram、Facebook、Tweeter 等)中测试您的链接