Search code examples
ioslocalnotificationmkmapitem

open map app slowly under didReceiveLocalNotification


I want to do a simple action, get a local notification and open apple map app. When I get the notification and then slide it, my app open first that is fine. But I need to wait about 10 seconds and the map app will be opened. why does it delay? It should be my app open and then the map does directly.

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
  CLLocationCoordinate2D rdOfficeLocation = CLLocationCoordinate2DMake(latitude,longitude);
  MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:rdOfficeLocation addressDictionary:nil];
  MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark]; 
  [item openInMapsWithLaunchOptions:nil];
}

Solution

  • You could try wrapping your code with this:

    dispatch_async(dispatch_get_main_queue(), ^{
        // Your code here
    });