I can open Google maps app using [NSURL URLWithString:#"comgooglemaps://...."]
But how to open Navigation mode?
The navigation mode is explained here, "Add navigation to your app" : https://developers.google.com/maps/documentation/ios-sdk/urlscheme
Try this code :
NSURL *testURL = [NSURL URLWithString:#"comgooglemaps-x-callback://"];
if ([[UIApplication sharedApplication] canOpenURL:testURL]) {
NSString *directionsRequest = #"comgooglemaps-x-callback://" + #"?daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York" + #"&x-success=sourceapp://?resume=true&x-source=AirApp";
NSURL *directionsURL = [NSURL URLWithString:directionsRequest];
[[UIApplication sharedApplication] openURL:directionsURL];
}
Related
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];
}
I want to open google map naviagation directly through googgle map App.
currenly i am using the code below
NSURL *testURL = [NSURL URLWithString:#"comgooglemaps-x-callback://"];
if ([[UIApplication sharedApplication] canOpenURL:testURL]) {
NSString *direction=[NSString stringWithFormat:#"comgooglemaps-x-callback://?saddr=%#,%#&daddr=%#,%#&x-success=sourceapp://?resume=true&x-source=AirApp", #"18.9750", #"72.8258", #"23.0300",#"72.5800"];
NSURL *directionsURL = [NSURL URLWithString:direction];
[[UIApplication sharedApplication] openURL:directionsURL];
}
else {
showAlert(AlertTitle, #"You don't have GoogleMaps App on this device. Please install it.");
//NSLog(#"Can't use comgooglemaps-x-callback:// on this device.");
}
}
But that is showing only direction and after that i need to click on navigation button in the App , is there is any way so that i can open google map navigation
directly.
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}.
I'm trying to open an iBook via my iPhone app using this code :
- (void)goToiBookStore {
NSURL *url = [NSURL URLWithString:#"itms-books://itunes.apple.com/us/book/le-secret-du-poids/id711921224"];
//NSURL *url = [NSURL URLWithString:#"itms-bookss://itunes.apple.com/us/book/le-secret-du-poids/id711921224"]; // Also tried
//NSURL *url = [NSURL URLWithString:#"https://itunes.apple.com/us/book/le-secret-du-poids/id711921224?l=fr&ls=1"]; // Also tried
// On teste si iBook installed
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
else {
[[[UIAlertView alloc] initWithTitle:#"iBooks" message:NSLocalizedString(#"installer ibooks lab", nil) delegate:self cancelButtonTitle:NSLocalizedString(#"annuler", nil) otherButtonTitles:NSLocalizedString(#"installer", nil), nil] show];
}
}
But, the URL does not send me to the iBook in iBooks but to the download page, is it normal ?
http://img4.hostingpics.net/thumbs/mini_953506photo.png
You can open iBooks, or open the store for that product, but not open a book directly.
If you want to open iBooks:
NSString *stringURL = #"ibooks://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
UPDATE 2019:
You can open iBooks to a specific book now by including the assetid of the book you want to open. Example:
ibooks://assetid/1396541327
Details available on the Apple.com website - https://support.apple.com/en-us/HT202929
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>