How to exit from Map App in IOS 6 i.e. return control back to app requesting directions?

泪湿孤枕 提交于 2019-12-13 18:22:19

问题


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.

Code:


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

       }];
    }

    }

回答1:


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.

Currently there is no way to use Mapkit to embed a map with directions within your app.



来源:https://stackoverflow.com/questions/15047322/how-to-exit-from-map-app-in-ios-6-i-e-return-control-back-to-app-requesting-dir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!