MKMapSnapshotter completionHandler never called in parent app when called from WatchKit

471 views Asked by At

I have this weird issue: I call the parent app with openParentApplication:reply: as normal.

It is nicely doing its job getting some data from the internet using async NSURLRequests but when I want to get a map image using MKMapSnapshotter (still in the parent app) its completion block is never called.

MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
    NSLog(@"completion handler is called"); //this never called
};

I tried to call with: snapshotter startWithQueue:on dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0) or dispatch_get_main_queue() etc. but nothing seems to work.

If I call the same code directly from WKInterfaceController or from the parent app it works just fine.

1

There are 1 answers

1
rmp On BEST ANSWER

I don't think you can call/use MKMapSnapshooter the way you are wanting to. When you use openParentApplication to make the request, it is opening your parent app in background mode and MKMapSnapshooter requires Foreground mode to deliver the final image.

as per Apple docs:

The snapshotter delivers the final image to your app only when it is running in the foreground. The snapshotter must render the final image while your app is in the foreground. If you start generating a snapshot while the app is in the background, or if your app moves to the background while a snapshot is in progress, this behavior delays the delivery of the snapshot until your app returns to the foreground.