Integrating native map app first direct to safari - iphone

In my app, I have integrated native map app for showing directions between two points on button action. I am using the following code.
- (IBAction)showRoute
{
NSString *urlString = [NSString stringWithFormat:#"http://maps.apple.com/maps? daddr=%#,%#&saddr=%f,%f",d_latitude,d_longitude, s_latitude, s_longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
But the problem is when click the button it first redirects to safari and then maps app - is there any way to miss out the safari step ?

In which iOS have you tried.? I tried on iOS 6 simulator works fine, opens the map app directly. In iOS simulator it opened safari has it doesn't have map app on simulator.
I have tried the below code on button action, its similar the one you used.
NSString* url = [NSString stringWithFormat:#"http://maps.apple.com/maps?daddr=%f,%f&saddr=Current%%20Location", 40.7142, 74.0064];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

Related

Opening an Native ios App inside an Another App?

i have this idiotic Question .
Is there any way open an another ios Application inside a view controller of a app.
I know we can open a another Ios app if we have url schema and the calling application goes to background and called application goes to background.
Is there any way ?? i just got a dream ,so am asking can we do it??
It is not possible to do it with the iPhone SDK. You can do this though by using Private APIs.
You can make it work on jailbroken devices.
But if you want to call native social apps like facebook or twitter you should use this code.
It works and apple approves it.
NSURL *fbNativeAppURL = [NSURL URLWithString:#"fb://"];
if ( [[UIApplication sharedApplication] canOpenURL:fbNativeAppURL])
{
[[UIApplication sharedApplication] openURL:fbNativeAppURL];
}
or
NSURL *twNativeAppURL = [NSURL URLWithString:#"twitter://"];
if ( [[UIApplication sharedApplication] canOpenURL:twNativeAppURL])
{
[[UIApplication sharedApplication] openURL:twNativeAppURL];
}

How to launch another app from an iPhone app

I am working on a map application in my iPhone app.
I have a button go.
When the user clicks this button in this method I want to check if user has installed the waze application on his iphone. If yes then navigate to waze application otherwise open iPhone's default map app.
Try to do this way :
NSString *wazeAppURL = #"waze://";
NSString *mapsAppURL = #"maps://";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:wazeAppURL]];
NSString *url = canOpenURL ? wazeAppURL : mapsAppURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Here, canOpenURL allows you to test if the Waze app is installed on your iPhone. if iPhone can open the url waze:// it means you already have the app and it will launch it. Otherwise it will launch the default Maps app. Safari won't be called.
To open an app you need to call
BOOL canOpenURL = [[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:#"app://"]];
if ( canOpenUrl ) [[UIApplication sharedApplication]
openURL:[NSURL URLWithString:url]];
To find all the url, go to this page: http://handleopenurl.com/
For waze in particular, http://handleopenurl.com/scheme/waze
hope this helps.
Note that on iOS you can also navigate to Google Maps -- and pass along the query string or geopoint. Here's one example of navigating to a specific geopoint:
if (self.mapView.userLocation.location) {
NSString *urlAsString = [NSString stringWithFormat:#"comgooglemaps://?q=%f,%f", self.mapView.userLocation.location.coordinate.latitude, self.mapView.userLocation.location.coordinate.longitude];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlAsString]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlAsString]];
}
}
Just a suggestion to enhance the user experience.

Linking to a Facebook Page with iOS6

So I am trying to link to a Facebook page on iOS6 from my app using
NSString* urlString = #"https://www.facebook.com/vioside";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
This opens up the Facebook app successfully but it doesn't go on my page. Anyone has an idea on how to link properly on iOS6?
The problem is that you may not use the short name. It has to be the 'id' for it to work currently.
iOS6 and facbook URLs not opening correctly in facebook app
I fixed this myself by removing the 'www' from the url. It's funny but with the 'www' is only opens the Facebook app, after removing it, safari is opened instead and views the proper page. Maybe it's an iOS6 bug but this worked for me
Replace "www.facebook.com" with "m.facebook.com":
NSString* urlString = #"https://m.facebook.com/vioside";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
it's working fine i tested it as like:-
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* urlString = #"https://www.facebook.com/vioside";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
}

How to move the user to a URL in Safari

I am making an app for a charity and Apple's review guidelines state that all donations must be made outside of the app in Safari, except for SMS donations, which we're not doing anyway. How do I make a button, that when tapped, goes to a specific URL in Safari? Thanks for your help!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"your.website.here"]];
And put it in an IBAction for your button.
There might be a problem connecting to your site try this:
NSURL *url = [NSURLWithString:#"your.website.here"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(#"%#%#",#"Failed to open url:",[url description]);
They actually have a post on it here:
How can I launch Safari from an iPhone app?
You can use this code in button click event
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"your url"]];
it automatically opens in safari

How to return to my iphone application after call ends?

I am able to call from my iphone application by using below code:
NSString *phoneNumber = #"tel://1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Now, i want to know how to return to my application back when the call ends ?
UIWebView *phoneCallWebview = [[UIWebView alloc] init];
// [self.view addSubview:phoneCallWebview];
NSURL *callURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", 9238928399]];
[phoneCallWebview loadRequest:[NSURLRequest requestWithURL:callURL ]];
As far as I'm aware, such interaction is impossible since your application has been demoted to background, and all UI interaction has been delegated to the Phone app, and the user.
I found this SO question
End call, don't return to app automatic in iphone 3.1 version
Which pointed to an article on apple dev forums
https://devforums.apple.com/message/128046 (dev account required)
Which says it was a change in iOS 3.1 but a "workaround" is
use UIWebView to open the tel: url, after the call, your app will relaunch, but you get the annoying do you want to make this call alert.
I have't verified this works as described, just thought I'd point it out
From iOS 5, use below...
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"12345678"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Just use telprompt:// instead of tel://
telprompt will prompt the user first, and when call ends,it will go back to your application.
NSString *myNumber = [#"telprompt://" stringByAppendingString:txtMobileNo.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:myNumber]];