【问题标题】:Swift: Sharing image to Twitter by deeplinking into the Twitter appSwift:通过深度链接到 Twitter 应用程序将图像共享到 Twitter
【发布时间】:2021-06-25 18:48:39
【问题描述】:

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

谢谢!

【问题讨论】:

  • 请分享您的代码以及到目前为止您尝试了什么
  • @zeytin 更新了问题。谢谢。
  • 嘿@KirillKudaev 你得到答案了吗?
  • @MojtabaHosseini 我做到了。谢谢!
  • 很高兴听到这个消息!如果它是您的答案,请不要忘记将其标记为答案:)

标签: ios swift twitter deep-linking sharing


【解决方案1】:

Spotify分享图片和标题!相反,它共享一个指向该站点的链接,其中包含正确的元数据以显示imagetitledescription 等。您可以通过阅读更多关于 Open Graph Protocol 的信息来实现此类链接Rich Link

总而言之,目标页面应在标题中包含以下内容:

<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 等)中测试您的链接

在 WhatsApp 上预览示例

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 2019-07-05
    相关资源
    最近更新 更多