YouTube URL Scheme tvOS

前端 未结 3 1943
既然无缘
既然无缘 2021-02-14 23:54

I am trying to open YouTube\'s app from my application with the URL scheme or the YouTube.com domain which opens YouTube\'s app directly on an iOS device.

This is the co

相关标签:
3条回答
  • 2021-02-15 00:08

    On Apple TV you can use this URL scheme to play a YouTube video in the YouTube app:

    youtube://watch/video_id
    

    Code example:

    func playVideoInYouTube(_ identifier: String) {
    
        if let url = URL(string: "youtube://watch/" + identifier),
            UIApplication.shared.canOpenURL(url) {
    
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
        else {
            // Inform the user about missing YouTube app
        }
    }
    

    To use the canOpenURL method, you have to add the scheme to the Info.plist file under key LSApplicationQueriesSchemes, as part of a schemes array. In XML it looks like this:

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>youtube</string>
    </array>
    
    0 讨论(0)
  • 2021-02-15 00:22

    I also encountered some issues playing youtube videos in the youtube app but I found a workaround, I used the XCDYouTubeKit library to play the youtube video's directly in my app. It's very easy to use and works fine so far.

    XCDYouTubeKit : https://github.com/0xced/XCDYouTubeKit

    0 讨论(0)
  • 2021-02-15 00:23

    Not necessarily positing this as a “correct" answer, but I think all YouTube links, on iOS at least, are handled by http, not something like youtube://.

    Source (looks to be from June 2015):

    https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/YouTubeLinks/YouTubeLinks.html

    0 讨论(0)
提交回复
热议问题