9

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 code I tried:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"youtube://results?search_query=trailer+%@",movieTitle]]];

and

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.youtube.com/results?search_query=trailer+%@",movieTitle]]];

But nothing seems to work. Any ideas on how to retrieve the URL scheme for YouTube's tvOS application?

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
BlackM
  • 3,927
  • 8
  • 39
  • 69
  • If you're able to get a hold of the `.ipa` you could look at the `.plist` to see what the URL Scheme is exactly or if there even is one. – Daniel Storm Dec 27 '15 at 15:19
  • What do you mean get a hold of the ipa? – BlackM Dec 27 '15 at 18:20
  • [.ipa - file extension](https://en.wikipedia.org/wiki/.ipa_%28file_extension%29). If you were able to get this you could unzip it and see the `.plist`. – Daniel Storm Dec 27 '15 at 19:22
  • I know what .ipa is but getting the Youtube's IPA without jailbreaking it won't be easy – BlackM Dec 28 '15 at 08:40
  • I'm not sure if you're able to backup an Apple TV to iTunes but if that's possible you can obtain the `.ipa`. – Daniel Storm Dec 29 '15 at 01:26
  • It seems that Apple TV 4 is not backing up on iTunes :/ – BlackM Dec 30 '15 at 00:12
  • I have a question. Have you tried url schemes like `tel` or `itms`? Do they work? – Amir Dec 31 '15 at 21:32
  • I've tried every URL Scheme I could find for YouTube, new and old, with no success. I also contacted YouTube's dev team with no response. I'd guess there is no URL Scheme for YouTube's tvOS application at the moment. – Daniel Storm Jan 02 '16 at 15:07
  • Does this answer your question? [How to play YouTube content on tvOS](https://stackoverflow.com/questions/32528624/how-to-play-youtube-content-on-tvos) – Matteo Gobbi Jul 07 '20 at 07:33

3 Answers3

4

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>
Ely
  • 8,259
  • 1
  • 54
  • 67
  • This is excellent and works. However to really be functional I am wondering if there is a way for my app to "know" when the video has completed playing and therefore to start another video? Simply put, if my app has a list of videoid's - can I cue them up / control them on the YouTube app? – Jim Jan 06 '21 at 15:52
-1

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

Luke
  • 9,512
  • 15
  • 82
  • 146
  • 2
    `youtube://` does indeed open the YouTube application on iOS. `[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"youtube://"]];` – Daniel Storm Jan 04 '16 at 13:14
  • Any evidence to suggest that scheme supports opening anything besides the app, though? Any kind of deep links, etc.? – Luke Jan 04 '16 at 13:29
  • Well, kind of... `[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"youtube://www.youtube.com/channel/UC6nSFpj9HTCZ5t-N3Rm3-HA"]];` – Daniel Storm Jan 04 '16 at 13:35
  • So it’s a direct swap for the `http` requests, looks like? – Luke Jan 04 '16 at 13:36
  • They probably built the tvOS app too fast for the tvOS launch that they cut off some features like this one. I think there is no reason not to implement it. – BlackM Jan 04 '16 at 15:49
  • 1
    That, or they want people using their own app for a little while, while the platform matures. Don’t want to fragment too much early on? – Luke Jan 04 '16 at 15:50
  • 1
    It's unfortunate that it's missing. I am wondering how restrictive it would be to distribute tvos apps that access the youtube content directly and hence break their TOS. http://stackoverflow.com/questions/32528624/how-to-play-youtube-content-on-tvos – El Dude Jan 04 '16 at 22:09
-1

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

Steven B.
  • 1,429
  • 2
  • 19
  • 38