iOS url scheme to open specific youtube page in youtube app - ios

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

Related

How to open ios app using url?

I want to open my ios app using URL schemes. I am able to open app using this.
But I want if app is not installed then app store should be opened where user can download app.
Is this possible? How can I do that?
EDIT
Explaining question step wise:
I have a mail in my inbox with a url.
I click on URL then
i. If app is installed in phone, app will launch.
ii. Otherwise app store will be opened to download app.
Thank
I handled it via my server side code:
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("com.myapp://");
setTimeout(function() {
if (!document.webkitHidden) {
location.replace("https://itunes.apple.com/app/xxxxxxxx");
}
}, 25);}
else if ((navigator.userAgent.match(/android/i)) || (navigator.userAgent.match(/Android/i))) {
location.replace("https://play.google.com/store/apps/details?id=packagename&hl=en");}
else {
location.replace("http://www.example.com");}
I put this in my www.mysite.com/download page & share this url via campaigns.
What you're describing is called Deferred Deep Linking (Deep Linking refers to using a link to open your app, even directly to a specific piece of content, and Deferred means that it works even if the app isn't installed first).
Unfortunately there's no native way to accomplish this yet on either iOS or Android. URL schemes don't work, because they always fail if the app isn't installed. Apple's new Universal Links in iOS 9 get closer, but you'd still have to handle redirecting the user from your website to the App Store
A free service like Branch.io (full disclosure: they're so awesome I work with them) can handle all of this for you though. Here's the docs page covering exactly how to create email links like you described: https://dev.branch.io/features/email-campaigns/overview/
If your App is not installed in device then, you can open app store using below lines of code:
NSString *iTunesUrlofApp = #"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];
Try below code:
if([[UIApplication sharedApplication] canOpenURL:url]){
// Means your app is installed, and it can be open
[[UIApplication sharedApplication] openURL:url];
}
else{
//Your app is not installed so, Open app store with your apps iTunes Url
NSString *iTunesUrlofApp = #"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];
}
After iOS 5 you can also use https:// to avoid redirections.
Edit:
Check the link to open app from url if installed: Universal links to open app from Url.

Open Link on Twitter App IOS

I have created a mail template on mailchimp. It consists of a twitter link. But an IPad or an IPhone user clicks on the link from his/her mail, the twitter link opens in the browser instead of the twitter app.
This does not happen in Android.
Any workarounds?
If you use a custom URL <a href="twitter://" than other Android/Desktop devices won't be able to open it. Twitter doesn't redirect with standard URLs from Safari and they should. But they do offer a "Open in app" button at the top left.
So if you want you could add two buttons in the email. One specifically for iOS: twitter://status?id=373205208664272897 and one for other devices https://twitter.com/support/status/373205208664272897.
Or you could create a site that reads the user agent of the device than determines which URL to redirect to.
The third option is just leaving it alone given that it's not really such a big issue in the grand scheme.
NSString *stringURL = #"twitter://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
From iPhone URL Schemes.

whatsapp URL Scheme doesn't give control back to app.

I am trying to share a link via Whatsapp and have read many tutorials as well. I am able to share my link successfully but the problem is that user doesn't come back to my app after sharing on whatsapp.
Here is the code I am using to share:
NSString *referralLink = [NSString stringWithFormat:#"some link here"];
NSString *textToSend = [[NSString stringWithFormat:#"whatsapp://send?text=%#",referralLink] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *whatsappURL = [NSURL URLWithString:textToSend];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
I know that I have to use URL Scheme to achive this and I have used it too. But I am not sure that I am using it in correct way.
Here is the screenshot of my .info file.
Behind the black bar, I have entered the bundle identifier. i.e com.abc.myapp
This is default behavior in iOS, only if the app developer of the app you are calling allows an option to send the user back to calling app will it work.
WhatsApp does not have such a feature and this is therefore not possible.
Also you should not use the whatsapp: url scheme in your apps info.plist. Doing this will make any app calling whatsapp: to open your app.
you should give your own url scheme(a unique identifier), probably your AppName. You are not supposed to use whatsapp
Now IOS 9 Do support the Apps to come back to the app when they are invoking any third party app being called using OpenURL scheme.
You can make a OS version based support at this moment unless you come to minimal support of IOS 9 for your application.

iOS open YouTube App with query (url schemes)

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.

Open Facebook app to customer's page?

I'm building an iOS app with the Facebook SDK.
One of the things my customer wants is a button that launches the Facebook app and shows their Facebook page. Is there some way to do this, perhaps using a URL?
Thanks.
iPhone has a bunch of URL schemes such as:
NSURL *url = [NSURL URLWithString:#"fb://<insert function here>"];
[[UIApplication sharedApplication] openURL:url];
Check this site out for more:
http://wiki.akosma.com/IPhone_URL_Schemes#Facebook
Also check out this SO post for more info:
https://stackoverflow.com/a/10416399/738262

Resources