Deeplink Schemas for YouTube, Amazon Prime Video and Vimeo – Swift


Here are some Swift functions to help you directly link to your content on different platforms from your iOS app. If the user has the YouTube, Amazon Prime or Vimeo app installed it will automatically open the content in the app. If they do not, it will open in the browser.

You will need the ID for each piece of content:


YouTube

func gotoYouTube(_ youtube_id: String)
{
    let app_link = URL(string : "vnd.youtube://www.youtube.com/watch?v=" + youtube_id)!
    UIApplication.shared.open(app_link, options: [:], completionHandler: {
        has_app in
        if !has_app
        {
            let http_link = URL(string : "https://youtube.com/watch?v=" + youtube_id)!
            UIApplication.shared.open(http_link, options: [:], completionHandler: nil)
        }
    })
}

Calling it:

gotoYouTube("k1648NUe3uo")

Amazon Prime Video

func gotoPrime(_ amazon_asin: String)
{
    let app_link = URL(string : "aiv://aiv/play?asin=" + amazon_asin)!
    UIApplication.shared.open(app_link, options: [:], completionHandler: {
        has_app in
        if !has_app
        {
            let http_link = URL(string : "https://www.amazon.com/dp/" + amazon_asin)!
            UIApplication.shared.open(http_link, options: [:], completionHandler: nil)
        }
    })
}

Calling it:

gotoPrime("B077Y3B768")

Vimeo

func gotoVimeo(_ vimeo_id: Int)
{
    let app_link = URL(string : "vimeo://app.vimeo.com/videos/" + String(vimeo_id))!
    UIApplication.shared.open(app_link, options: [:], completionHandler: {
        has_app in
        if !has_app
        {
            let http_link = URL(string : "https://vimeo.com/" + String(vimeo_id))!
            UIApplication.shared.open(http_link, options: [:], completionHandler: nil)
        }
    })
}

Calling it:

gotoVimeo(347097960)

For more URL Deep Link Schemas check out http://urlgeni.us.