iOS open YouTube App with query (url schemes)
Asked Answered
Z

10

21

Is there an URL Scheme to open the YouTube iOS app with a specified search query?

I tried:

NSString *stringURL = @"http://www.youtube.com/results?search_query=foo";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

But this will open Safari instead of the YouTube Application.

Zulemazullo answered 9/9, 2013 at 9:45 Comment(0)
C
24

You can't use this http://www.youtube.com/results?search_query=foo for opening youtube app. If you use the above url it'll open the safari instead of youtube app.

There are only three URLSchemes available for opening youtube app:

  • http://www.youtube.com/watch?v=VIDEO_IDENTIFIER
  • http://www.youtube.com/v/VIDEO_IDENTIFIER
  • youtube://

Reference: iPhoneURLScheme

Committee answered 9/9, 2013 at 12:23 Comment(5)
ok, too bad. I thought there would be an undocumented way. This is such an obvious feature. I don't get it. Then Safari has to do it for now. Thanks.Zulemazullo
this is not working with my channel. Can you check the two linked questions?Bellbird
Is youtube a special case whereas other apps need to use the normal url scheme (i.e. myappname://)?Threesome
I tried now on ios10. Only the youtube:// url scheme seems to work.Judsen
can't we send multiple videos so it would generate a playlist?Gertrudgertruda
A
16

this is working fine in iOS 9

youtube://www.youtube.com/channel/<channel-id>

Arrowhead answered 28/9, 2015 at 12:30 Comment(2)
With iOS 9 even http links like youtube.com/watch?v=hVxPJ9heetc, will open in youtube app, as youtube has implemented Universal linking.Frieze
This has stopped working for me IOS 1o, it keeps opening the mobile site and not the app, can I add something to the url to force app?Frighten
C
9

Update for Swift 3 and iOS 10+

OK, there are two easy steps to achieve this:

First, you have to modify Info.plist to list Youtube with LSApplicationQueriesSchemes. Simply open Info.plist as a Source Code, and paste this:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>youtube</string>
</array>

After that, you can open any youtube URL inside Youtube application by simply substituting https:// with youtube://. Here is a complete code, you can link this code to any button you have as an Action:

@IBAction func YoutubeAction() {

    let YoutubeQuery =  "Your Query"
    let escapedYoutubeQuery = YoutubeQuery.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
    let appURL = NSURL(string: "youtube://www.youtube.com/results?search_query=\(escapedYoutubeQuery!)")!
    let webURL = NSURL(string: "https://www.youtube.com/results?search_query=\(escapedYoutubeQuery!)")!
    let application = UIApplication.shared

    if application.canOpenURL(appURL as URL) {
        application.open(appURL as URL)
    } else {
        // if Youtube app is not installed, open URL inside Safari
        application.open(webURL as URL)
    }

}
Coumarone answered 16/3, 2017 at 6:22 Comment(1)
iOS 12, canOpenURL returns false for any link with youtube://Gertrudgertruda
H
4

It can be opened using

vnd.youtube:///

(note three slashes are set)

Hotpress answered 3/7, 2015 at 18:24 Comment(0)
A
3

If there is a supported YouTube application search URL scheme, it isn't well documented (and will probably be fragile). You can open YouTube app itself directly using:

youtube://

You can play specific videos using:

http://www.youtube.com/watch?v=VIDEO_IDENTIFIER

I'd approach this problem by querying the list directly, and either display the results in a webview. Ideally, you don't want to replicate the YouTube app (there's already one on the app store after all), so it would be better to find the specific video identifier some other route.

Affirmative answered 9/9, 2013 at 10:0 Comment(0)
M
3

You can open the YouTube iOS app in this fashion:

Videos

<a href="youtube://dQw4w9WgXcQ">Open in YouTube</a>
<a href="youtube://watch?v=dQw4w9WgXcQ">Open in YouTube</a>

Users and Channels

Not possible at this time. (Source: extensive testing.)

Playlists

Unknown/Untested

Mahoney answered 10/10, 2014 at 4:0 Comment(1)
I was able to get at channel to open in the app using the custom URL "youtube://www.youtube.com/c/yourcustomname"Chiliasm
S
3

If you want to open the YouTube iOS app with a search query use this syntax:

youtube:///results?q=search%20query

(replace search%20query with search terms without quotes)

Note: the above syntax has three slashes instead of two.

(Works as of 20160420)

Shantung answered 23/12, 2014 at 1:51 Comment(0)
A
2

For iOS 11 this should works:

youtube://www.youtube.com/<channel-id>
Allspice answered 25/7, 2017 at 7:28 Comment(1)
youtube://www.youtube.com/<channel-id> doesn't work. I need to add channel: youtube://www.youtube.com/channel/<channel-id>Gambia
H
0

To open a Youtube link that opens in app, from a webpage (safari or any browser), and this works for opening from a javascript function too, you need to send a proper form query to Youtube:

<form id='form' action='https://m.youtube.com/watch?v=' method='get'>
<input type='hidden' name='v' id='v' value='XgQrzkvvOO4'>
</form>

This is for mobile sites. For normal browsers change "'https://m.youtube.com/watch?v=" to "'https://youtube.com/watch?v="

If you need a link or button simply change the input type to button.

EDIT: this method no longer works on iphone as of latest changes IOS and YT. Still searching for a method to open the Youtube APP from a script, without being asked by the browser yes or no.

Highminded answered 8/11, 2018 at 8:16 Comment(0)
Q
0
youtube://results?search_query=<your query>
Quoits answered 18/12, 2023 at 19:4 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Christinachristine

© 2022 - 2024 — McMap. All rights reserved.