Kirill
Kirill

Reputation: 889

Swift: Sharing image to Twitter by deeplinking into the Twitter app

I'm trying to share an image and a caption from an iOS app to Twitter without using the Twitter Kit library. Ideally, it should work exactly like the Spotify sharing I attached to this post. Any thoughts on this?

I scanned through Twitter documentation but I don't see much in there on this topic.

I've also tried using Apple's SLComposeViewController but the issue there is that images are being displayed as URLs instead of images when they appear on Twitter:

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)
                    }

Please don't mark this question as a duplicate unless the solution offers instant deep linking like on the gif attached.

Thank you!

Twitter sharing on Spotify

Upvotes: 2

Views: 2042

Answers (1)

Mojtaba Hosseini
Mojtaba Hosseini

Reputation: 120002

Spotify is NOT sharing an image and a caption! Instead, it shares a link to the site which contains the proper meta data to show the image, title, description and etc. You can achieve this kind of links by reading more about the Open Graph Protocol and Rich Link

In summary, the destination page should contain these in the 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" />

Example taken from the ogp.me

Preview of the example on Tweeter

Demo


Note that remember some social media and platforms support different meta! Make sure to TEST your link in all of your target platforms (WhatsApp, Telegram, Facebook, Tweeter, etc.)

Preview of the example on WhatsApp

Demo 2

Upvotes: 6

Related Questions