如何在IOS 6中退出Map App,即将控制权返回到应用程序的请求方向? [英] How to exit from Map App in IOS 6 i.e. return control back to app requesting directions?
问题描述
用户点击方向"按钮后,我正在使用MKMapItem
从我的应用程序中启动地图"应用程序. Map应用程序可以很好地显示从当前位置到地址的方向.但是,如果我不再希望查看路线,该如何返回我的应用程序?以下是我附在IBAction
上的代码.
I am using MKMapItem
to launch Map app from within my app after the user taps 'Directions' button. The Map app comes up fine showing directions from current location to a address. But how do I go back to my app, If I no longer want to see Directions? Below is my code attached to IBAction
.
代码:
- (IBAction)pressDirectionsButton:(id)sender {
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
NSString *addressString = [NSString stringWithFormat:@"%@,%@,%@,%@,%@",
self.currentlySelectedTemple.houseNumber,
self.currentlySelectedTemple.street,
self.currentlySelectedTemple.city,
self.currentlySelectedTemple.state,
self.currentlySelectedTemple.country];
[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) {
//Convert CLPlacemark to an MKPlacemark
CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc]
initWithCoordinate:geocodedPlacemark.location.coordinate addressDictionary:geocodedPlacemark.addressDictionary];
//Create a map item for geocoded address to pass to Maps app
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:geocodedPlacemark.name];
//Set Directions mode to Driving
NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving};
//Get the "Current User Locations" MKMapItem
MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation];
//Pass the current location and destination map items to Maps app
[MKMapItem openMapsWithItems:@[currentLocationMapItem, mapItem] launchOptions:launchOptions];
}];
}
}
推荐答案
无法(以编程方式)返回到您的应用程序,因为您不再在应用程序中,而是在Maps应用程序中.执行openMapsWithItems:launchOptions:
后,将调用您的App Delegate的applicationdDidEnterBackground:
方法.
There is no way to go back to your app (programatically), as you are no longer in your app, but in the Maps app. After executing openMapsWithItems:launchOptions:
, your App Delegate's applicationdDidEnterBackground:
method is called.
当前无法使用Mapkit在应用程序中嵌入带有方向的地图.
Currently there is no way to use Mapkit to embed a map with directions within your app.
这篇关于如何在IOS 6中退出Map App,即将控制权返回到应用程序的请求方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!