Swift:通过深层链接到 Twitter 应用程序将图片分享到 Twitter 在 Tweeter 上预览示例WhatsApp 示例预览

问题描述

我正在尝试在不使用 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 所示。

谢谢!

Twitter sharing on Spotify

解决方法

Spotify 分享图片和标题!相反,它共享一个指向站点的链接,该链接包含正确的元数据以显示 imagetitledescription 等。您可以通过阅读有关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 上预览示例

Demo


请注意记住一些社交媒体和平台支持不同的元!确保在所有目标平台(WhatsApp、Telegram、Facebook、Tweeter 等)中测试您的链接

WhatsApp 示例预览

Demo 2