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.
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
this is working fine in iOS 9
youtube://www.youtube.com/channel/<channel-id>
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)
}
}
It can be opened using
vnd.youtube:///
(note three slashes are set)
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.
You can open the YouTube iOS app in this fashion:
Videos
Open in YouTube
Open in YouTube
Users and Channels
Not possible at this time. (Source: extensive testing.)
Playlists
Unknown/Untested
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)
For iOS 11 this should works:
youtube://www.youtube.com/<channel-id>
According to the latest Apple Developer Documentation, youtube cannot be opened using youtube:// url scheme instead it should be as mentioned in the below link.
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/YouTubeLinks/YouTubeLinks.html
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.
Related
I used to have a UIButton that would load an URL in the form of itms://example.com this when pressed would load the relevant item within the AppStore application on iOS (rather than in the browser).
However that is no longer working for me. If I switch the URL to https:// then the relevant page opens in the browser but if I use itms or itms-apps then it does nothing. Any ideas why or if there’s a new way of doing this?
The use case is to refer people from one app to download another from the AppStore.
Using the http link should open directly into App Store app via universal links.
// open Google Earth in the app store
UIApplication.shared.open(URL(string: "http://itunes.apple.com/us/app/google-earth/id293622097?mt=8")!, options: [:], completionHandler: nil)
If you wish to keep the experience inside of your app, then use SKStoreProductViewController as pointed out by rmaddy
I have set up Universal links in my iOS app, and it works with full URL like : example.com/path/
Recently, I want short URL like: t.cn/m , which map to example.com/path/ , can be opened in my App directly. So I added appplinks:t.cn at association domain in Capabilities.
But it doesn't work. It can't be opened directly in my App.It's opened with safari and i have to click the "open" button on pull-down-banner in safari to open in my App.
It seems like short URL can't be opened directly in my App, can it?
try applink instead of appplinks
from documentation
I have two applications and i want to open them from each other (like facebook opens messenger).
After a little search i found that i have to know the url scheme of my app, but i don't know how can i declare it. In my urlSchemes are only facebook's schemes.
var url = NSURL(string: "")
UIApplication.sharedApplication().canOpenURL(url!)
I found that code and as i understand i have to put in the url my urlScheme.
Any help?
Here is a good tutorial on setting up URL Schemes within you app: https://dev.twitter.com/cards/mobile/url-schemes
Incase this tutorial disappears, heres the info:
Configure our Xcode project
Go to Your Target > Info > URL Types
You need to define your custom URL type. Remember, you want to open the app via birdland://, so that will be your URL scheme. We also need to assign an unique identifier to the scheme. Apple recommends that you use reverse DNS notation to ensure that there are no name collisions on the platform, e.g com.mycompany.ios.
That’s it! You’ve configured the app with simple support for the URL scheme birdland://. There is, of course, much more that you can do with Custom URL Schemes. To find out more, check out Apple’s documentation.
Now, to check that our registered URL scheme works, we’ll head out to Safari. Press the “Home” button in the Simulator (or press command-shift-H) to reach the Home Screen. Open Safari.
Next, type birdland:// in the address bar of Safari. Just as you can with http:// URLs, you’re asking Safari to open the “birdland” scheme. Press Go.
NSString *openAppURL = #"yourappname://";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:openAppURL]];
//check if app is installed or not
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:openAppURL]];
So I'm trying to figure out how youtube links work on a device. If you were to tap a youtube link in safari/anywhere it would open up the youtube app if it's available or just go to the video in safari. I'm trying to emulate this with my app.
I'm just confuse how to open a app with a valid web url. I understand that I can open a app with a url scheme such youtube:// but that not the same as www.youtube.com
These apps implement what's called URL Schemes.
Here's a pretty good tutorial for setting up your own app with a URL scheme: http://www.idev101.com/code/Objective-C/custom_url_schemes.html
Is there anyway to use an iOS URL Scheme to open the YouTube to a particular user's profile I've tried youtube://user/myusername but that did not seem to work.
To open a Youtube page in Youtube app (if it's installed on the device)
you can check whether the device can open the page:
// URL scheme for youtube app
NSString *youtubeURL = #"youtube://www.youtube.com/user/";
// Page name(or channel name)
NSString *youtubePageName = #"YourPageName";
// Check if the device can open in Youtube app or not.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString: [youtubeURL stringByAppendingString:youtubePageName]]]){
// Open in Youtube app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: [youtubeURL stringByAppendingString:youtubePageName]]];
}else{
// If device cannot open in youtube app, open the page in browser.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.youtube.com/user/YourPageName"]];
}
This solution worked for me
iOS 9 edit: Target app's URL scheme must be added to info.plist under LSApplicationQueriesSchemeskey.
Here is a related post: iOS 9 not opening Instagram app with URL SCHEME
This forum post's lack of responses indicates there probably isn't a way to do this currently: YouTube iOS URL Scheme for Channels
But you may be able to request that feature on YouTube's iOS app feedback page. And in the meantime, I'd recommend just linking to users' HTML YouTube pages.
No, few weeks ago I was looking for the same, but i didn't found anything. Instead I've opted for use a UIWebView to show the youtube channel or using the openURL: UIApplication's method to open the channel with Safari.
If you want to save some time, you can use the easy-to-implement TSMiniWebBrowser's control at this Github page.
Here is the youtube Channel Url scheme, try to load it in UIWebView and it will works.
http://m.youtube.com/#/user/channel_name for e.g http://m.youtube.com/#/user/whartonmagazine