Go to iPhone maps app from another app - objective-c

I'm writing an app where I want the user to be able to get directions. I know about the google API, and I have that implemented, but I was wondering about ways to jump directly to the native Maps app and give the user directions instead. I think I've seen it done before, but I could be mistaken.
Any help is much appreciated.

You can open the maps app by using regular URL that points to Google Maps. From the Apple URL Scheme reference:
The maps URL scheme is used to show geographical locations and to generate driving directions between two points. If your application includes address or location information, you can use map links to forward that information to the Maps application on iOS and the Google Maps website on other platforms.
Unlike some schemes, map URLs do not start with a “maps” scheme identifier. Instead, map links are specified as regular http links but are targeted at the Google Maps servers. The following examples show the strings you would use in Safari and in a native application to show a map of the city of Cupertino, California.
HTML link:
Cupertino
Note that on a device that does not have maps installed (not sure if those even exist), the link will open in a regular browser, since it is simply an HTTP link.
To open the URL, you can present the link in a UIWebView, or you can use code to open it. for example:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=Cupertino"]];
If you wanted to pass in a custom location and open it when the user taps a button, you can make a method like this:
- (IBAction) openMapsAppAndShowLocation:(NSString *)locationToShow{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.google.com/maps?q=%#", locationToShow]]];
}
If you wanted, you could refactor the method to take latitude/longitude pair too. That might look like this:
- (IBAction) openMapsAppAndShowLatitude:(double)latitude andLongitude:(double)longitude{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.google.com/maps?q=\"%f,%f\"", latitide, longitude]]];
}

You can use either this:
NSString *latlong = #"-56.568545,1.256281";
NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?ll=%#",
[latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
this,
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString: #"http://maps.google.com/maps?q=London"]];
or this
[someUIApplication openURL:[[NSURL alloc] initWithString: #"http://maps.google.com/maps?q=London"]]
You can even specify the zoom level using the z flag (values between 1-19):
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?z=8"]];
That should invoke the Google Maps app. I think that these instructions only work on the actual device and NOT in the simulator. Good luck and comment below if you have any problem with the snippets :)

Very simple
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=London"]];
Easy as a kiss

#Moshe
Note that on a device that does not have maps installed (not sure if those even exist)
Take an iPhone simulator for example.

Related

maps on iOS 8 when launching a map select which map app use

Is there any way to when launching a map if the user has more than one map app(native iOS Map and google maps) have some sort of prompt to select the map app you want to open it? or do I need to create specific methods for each map app that I have installed on the device.
You have to do the GUI yourself, but these are basically what you need to do. They are relatively simple:
Set up the URL (assume you have lat, lon):
For apple map
NSString *urlString = [[NSString alloc] initWithFormat:#"http://maps.apple.com/?q=%.5f,%.5f",
lat, lon];
For google map
NSString *urlString = [[NSString alloc] initWithFormat:#"comgooglemaps://?q=%.5f,%.5f",
lat, lon];
or other maps...
Then, open it
NSURL* url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
If you're making about your own apps, you can use the URL Scheme on iOS to open the Google Maps app, perhaps add some deep linking too.
But if you're talking about opening the maps from contacts, or the notes app, you might need to
Make Google Maps your default maps app on iOS with MapsOpener tweak

Facebook share functionality is not working in iOS8

I have implemented Facebook sharing functionality using social framework. I have configured the Facebook account using device setting. When I installed the Facebook app on device, sharing is not working as expected.
When share window appears, it only has the image for sharing and no initial text and URL.
iOS8 - Share functionality is working properly if I remove the Facebook app from device.
iOS7 - Share functionality is working properly even the Facebook app is on device.
I am not sure where it is a framework issue or something is missing?
SLComposeViewController *facebookShareVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSString *imagePath = [NSString stringWithFormat:#"%#/%#_%#_%#.gif", [[STInteractionManager sharedManager] getAppLibraryCacheDirectory], article.journalID, article.volume, article.issueNumber];
UIImage* img = [[STInteractionManager sharedManager] imageNamedFromDocuments:imagePath];
[facebookShareVC setInitialText:self.articleTitle];
[facebookShareVC addURL:[NSURL URLWithString:[self.url stringByReplacingOccurrencesOfString:#"?dispform=ios-device" withString:#""]]];
[facebookShareVC addImage:img];
[self presentViewController:facebookShareVC animated:YES completion:nil];
If you want to pre-fill the fields, you shouldn't use the Facebook SDK at all. Instead, use the Social framework provided by Apple. With only a few lines of code, you can trigger the SLComposeViewController.

playing a youtube movie from url in objective C

I have a tableview which contains youtube urls.
http://www.youtube.com/v/M67PNWvKdg0&autoplay=1
I am trying to play the video file with the following piece of code. I also imported the media framework.
Video *video = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSURL *urlString=[NSURL URLWithString:video.url];
//NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
//pathForResource:#"Video1" ofType:#"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:urlString];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
What it does for now is it pops up a movie player but then immediately goes back to my tableview. Does anybody knows what the problem is?
Thanks in advance
Are you working on iOS 6? I found difficulty in playing Youtube videos through MPMoviePlayerController, so I found out this to be very useful.
This has MPMoviePlayerController only...
And this would work well for Versions < iOS 6 too.
You can't play youtube videos via Media Player. You have only two solutions: open the link via external app (just open it and iOS will run Safari or YouTube.app if installed) or you can implement your own view with UIWebView and open the link inside WebView.
May be this link would help you, and one more thing is the video plays only on device cant test on a simulator.
There's another way but you have to be a little adventurous.
You can use a third party rtsp framework of which there are a few.
Then you need to link to the m.youtube.com, this is the rtsp version of youtube that Android and other phones will get you to.
If you try to open this link in safari on the iphone the page redirects to the h264 links.
You can open the url in an uitableview and change the user-agent tag. Or simply copy the links you want into a table.
Are all youtube videos automatically converted to h264 now, at one time I remember they were a subset of the rtsp pages.
If you have an Android device you can access this page in a webview quite easily.
here check this link out.
http://streammore-tv.tumblr.com/post/34794206547/welcome

Open native Twitter App from my Application using IBAction

I'd like to implement the natvie Twitter App into my iOS Application.
I've already done that with Facebook by using the URL Schemes. But I weren't able to find such thing for Twitter.
For Facebook I used:
-(IBAction)facebook:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"fb://"]];
}
But when I try to use
#"Twitter" or #"twitter" or #"tw"
nothing happens.
Would be great if you guys could help me out. I haven't found anything in the Interweb :/
If there is something just like it please :)
Thanks in advance :)
Did you try:
twitter://
ex:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"twitter://user?screen_name=username"]];

How to dial a number in Iphone for India

I want to dial a number from IPhone simulator for India. I have tried this on a button click:
-(void)makeaCall
{
NSURL *phoneNumber = [[NSURL alloc] initWithString: #"tel:1-800-180-2222"];
[[UIApplication sharedApplication] openURL: phoneNumber];
}
But it's not showing any action of dialing any number.
Please help me with this.
you can't make a phone call from the simulator you will need a real phone for that.
but you can simulate an incoming call by selecting Hardware > Toggle In-Call Status Bar. also the incoming call should trigger in the app delegate the method applicationWillResignActive.
You might have to try that on a real phone, the simulator is a simulator after all and might not be able to make calls.