2013-02-24 4 views
1

Я использую MKMapItem для запуска приложения Карты из моего приложения после того, как пользователь нажал кнопку «Направления». Приложение «Карта» прекрасно отображает направления от текущего местоположения до адреса. Но как мне вернуться в мое приложение, если я больше не хочу видеть «Направления»? Ниже мой код прилагается к IBAction.Как выйти из приложения Map в IOS 6 i.e вернуть управление обратно в приложения, запрашивающие указания?

Код:


- (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]; 

     }]; 
    } 

    } 

ответ

2

Там нет никакого способа, чтобы вернуться в приложение (программно), так как вы больше не в вашем приложении, но в приложении Maps. После выполнения openMapsWithItems:launchOptions: вызывается метод applicationdDidEnterBackground: вашего делегата приложения.

В настоящее время не существует способа использовать Mapkit для встраивания карты с указанием направления в вашем приложении.