launch youtube channel in youtube app - ios

For launching video on youtube app, I am using below code.
NSURL *instagramURL = [NSURL URLWithString:#"youtube://foo"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSLog(#"opening youtube app...");
NSString *stringURL = #"http://www.youtube.com/watch?v=H9VdapQyWfg";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
} else {
// open in UIWebView in WebViewViewController
WebViewViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:#"webinterface"];
secondView.headerLabel = #"YouTube";
secondView.webPath = #"http://www.youtube.com/watch?v=H9VdapQyWfg";
[self.navigationController pushViewController:secondView animated:YES];
}
Now client changed the mind and asking to put channel in iPhone app.
For testing, I used link http://www.youtube.com/user/richarddawkinsdotnet
BUT when I use this link, instead of youtube app, it always opens in SAFARI. :(
Any idea/ suggestion on how can I open channel in YouTube app with link provided?

You're code's going wrong because, although you're checking if you can open the youTube URL more or less correctly, you're then just opening a web address, which will always open in Safari.
This is the code I've just used, which is working for me. You might want to modify the else statement if you want to fallback to using a webviewcontroller as this will open Safari if the youtube app isn't installed.
NSString *channelName = #"TheNameOfTheChannel";
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:#"youtube://user/%#",channelName]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.youtube.com/user/%#",channelName]];
if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
// Can open the youtube app URL so launch the youTube app with this URL
[[UIApplication sharedApplication] openURL:linkToAppURL];
}
else{
// Can't open the youtube app URL so launch Safari instead
[[UIApplication sharedApplication] openURL:linkToWebURL];
}

Same answer, but shorter:
if (![[UIApplication sharedApplication] openURL: [NSURL URLWithString: #"youtube://user/%channelName%"]]) {
NSURL *webURL = [NSURL URLWithString:#"http://www.youtube.com/user/%channelName%"];
[[UIApplication sharedApplication] openURL: webURL];
}
and twitter:
if (![[UIApplication sharedApplication] openURL: [NSURL URLWithString: #"twitter://user?screen_name=%channelName%"]]) {
NSURL *webURL = [NSURL URLWithString:#"http://twitter.com/%channelName%"];
[[UIApplication sharedApplication] openURL: webURL];
}
And here is a more exhaustive list of apps:
http://wiki.akosma.com/IPhone_URL_Schemes

youtube://user/<channel-id> stopped working in iOS 9 so i research and found this working well now in iOS 9
youtube://www.youtube.com/channel/<channel-id>

Related

I want to open any thirdparty application related to Hotel Booking like MakeMyTrip through my application

I want to open any thirdparty application related to Hotel Booking ( like MakeMyTrip ) through my application.
If any one implemented any please help
Yes you can, URL Schemes are the only way to communicate between apps.
NSURL *Url = [NSURL URLWithString:#"Type your application url here"];
[[UIApplication sharedApplication] openURL:Url];
You can do,
NSURL* makeMyTripURL = [NSURL URLWithString:#"makemytrip://"];
NSURL* appStoreURL = [NSURL URLWithString:#"https://itunes.apple.com/in/app/makemytrip-flights-hotels/id530488359?mt=8"];
if ([[UIApplication sharedApplication] canOpenURL:makeMyTripURL])
{
[[UIApplication sharedApplication] openURL:makeMyTripURL];
}
else
{
[[UIApplication sharedApplication] openURL:appStoreURL];
}

How can I open the link on an application? [duplicate]

This question already has answers here:
How can I launch Safari from an iPhone app?
(7 answers)
Closed 7 years ago.
I added a code for Xcode from the internet.
This one:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.youtube.com"]];
It took me to www.youtube.com on the Safari browser, what if I have youtube application? how can it open that from the application in my iPhone?
p.s I’m a newbie
- (IBAction)btnYoutube:(id)sender {
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:#"youtube://user/%#",#"toyotaleasing"]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.youtube.com/user/%#",#"toyotaleasing"]];
if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
// Can open the youtube app URL so launch the youTube app with this URL
[[UIApplication sharedApplication] openURL:linkToAppURL];
}
else{
// Can't open the youtube app URL so launch Safari instead
[[UIApplication sharedApplication] openURL:linkToWebURL];
}
}
Use URL scheme for youtube : youtube://
Eg.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"youtube://www.youtube.com/watch?v=<video-id>"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"youtube://www.youtube.com/watch?v=<video-id>"]];
}
Hope, it'll help you.

can we force to open facebook link in browser not in native app iphone

Is it possible to force through your application that it will open the web link in safari only not in native app like facebook, twitter or web view etc.
So far i searched found only this code that is used for opening the link
NSURL *url = [NSURL URLWithString:#"www.facebook.com"];
[[UIApplication sharedApplication] openURL:url];
But what can we paste in else there below?
if ([[UIApplication sharedApplication] canOpenURL:nsurl]){
[[UIApplication sharedApplication] openURL:nsurl];
}
else {
//Open the url as usual, but how?
}
Use http://facebook.com/ instead of www.facebook.com
this will force a link to open in Safari instead of native app*
NSURL *myURL = [NSURL URLWithString:#"http://facebook.com/"];
if ([[UIApplication sharedApplication] canOpenURL:myURL]) {
[[UIApplication sharedApplication] openURL:myURL];
}
You can use a webView to open any link of your choice.

How to redirect url to either the Soundcloud or youtube app if downloaded

So when I am wanting to go to the twitter app if the user has it downloaded and safari (a browser) if not. I write this code:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:#"%#", #"twitter://user?screen_name=foo"]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://www.twitter.com/foo"]];
}
if I want to do the same with facebook I do this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://www.facebook.com/TragicClothing"]];
But what happens when I want to do this with Soundcloud (and Youtube)?
Is there an equivelant twitter://user?screen_name=foo for them both?
Please bare in mind that I want to go to a user page (foo) of Soundcloud (and Youtube)
my code for youtube:
NSString *channelName = #"channel";
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:#"youtube://user/%#",channelName]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.youtube.com/user/%#",channelName]];
if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
// Can open the youtube app URL so launch the youTube app with this URL
[[UIApplication sharedApplication] openURL:linkToAppURL];
}
else{
// Can't open the youtube app URL so launch Safari instead
[[UIApplication sharedApplication] openURL:linkToWebURL];
}
This is a correct mode to open an app and check if is installed:
if you have a tex area or label you have to use:
NSString *tweetUser;
tweetUser = self.myLabel.text;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"twitter://user?screen_name=%#", tweeUser]]];
the correct method is:
- (IBAction)tweet:(id)sender {
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:#"twitter://app"]]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"twitter://user?screen_name=<neme here>"]];
}else{
[self notInstalledAlert];
}
}
- (UIAlertView*) notInstalledAlert {
return [[UIAlertView alloc]
initWithTitle:#"Twitter Not Installed!"
message:#"Twitter must be installed on the device in order to open app"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
}
for example youtube have:
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:#"youtube://app"]]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"youtube://user/donotrecords"]];
this is soundcloud, but you need user ID not name:
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:#"soundcloud://app"]]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"soundcloud:users:id"]];
The URL scheme to access a user page in the SoundCloud iOS app is soundcloud://users/{USER_ID}.

Sygic URL scheme - App does not open

I am trying to integrate the most popular navigation apps into my app, and all of those I chose work, except for Sygic.
Following this guide, I wrote the code:
NSString *URL = [NSString stringWithFormat:#"com.sygic.aura://coordinate|%f|%f|drive",
self.coordinate.longitude,
self.coordinate.latitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URL]];
But when the code is run, Sygic doesn't open, nothing happens.
Checking [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"com.sygic.aura://"]] returns YES when the app is installed and NO when it's not (as it should).
I tested using "Sygic Brasil" and "Sygic (All Regions)", version 13, but neither will open.
I also tried percent-escaping the URL string, and that didn't work either.
you try following code,
NSString *URL = [NSString stringWithFormat:#"com.sygic.aura://coordinate|%f|%f|drive",
self.coordinate.longitude,
self.coordinate.latitude];
NSURL *newURL = [NSURL URLWithString:[URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
if(newURL)
{
[[UIApplication sharedApplication] openURL:newURL];
}
else
{
NSLog(#"Something wrong with lat or long or both");
}

Resources