ios - Swift:通过深度链接到 Twitter 应用程序将图像共享到 Twitter

标签 ios swift twitter deep-linking sharing

我正在尝试在不使用 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 分享图片和标题!相反,它共享一个指向网站的链接,其中包含适当的元数据来显示图像标题描述等。您可以实现通过阅读有关 Open Graph Protocol 的更多信息来获取此类链接丰富链接

总之,目标页面应在 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

Tweeter 上的示例预览

Demo


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

WhatsApp 上的示例预览

Demo 2

关于ios - Swift:通过深度链接到 Twitter 应用程序将图像共享到 Twitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66859316/

相关文章:

swift 问题: how can we init an non-optional variable in a if else block if it's of protocol type?

ios - 无法更改 Xcode 项目名称 - 3 个目标 - Swift Xcode 6.0.1

swift - 在 View 和 View Controller 之间委托(delegate)

ios - 如何存储和访问 Twitter Fabric 登录 session (iOS/Swift)?

javascript - req.body.tweet返回值且未定义

ios - NSLogv C 字符串编码

ios - 在 ScrollView 中使用 2 个垂直堆栈 View ,根据内部 View 增加高度

python - 使用 Tweepy 将推文插入 MySQL DB

ios - iOS 是否可以并允许下载资源包并从中加载一些字符串?

objective-c - 使用 AVFoundation 捕获图像时无法设置图片大小