[英]Swift: Sharing image to Twitter by deeplinking into the Twitter app
我正在尝试在不使用 Twitter 套件库的情况下将 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的更多信息来实现此类链接协议和富链接
总之,目标页面应该在 header 中包含这些:
<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 的示例
请注意,请记住一些社交媒体和平台支持不同的元! 确保在所有目标平台(WhatsApp、Telegram、Facebook、Tweeter 等)中测试您的链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.