簡體   English   中英

Swift:通過深度鏈接到 Twitter 應用程序將圖像共享到 Twitter

[英]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 上分享 Twitter

Spotify共享圖像和標題,而是共享一個指向該站點的鏈接,其中包含適當的元數據以顯示imagetitledescription等。您可以通過閱讀有關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 的示例

Tweeter 上的示例預覽

演示


請注意,請記住一些社交媒體和平台支持不同的元! 確保在所有目標平台(WhatsApp、Telegram、Facebook、Tweeter 等)中測試您的鏈接

在 WhatsApp 上預覽示例

演示 2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM