MKMapSnapshotter completionHandler never called in parent app when called from WatchKit

隐身守侯 提交于 2019-12-12 03:36:27

问题


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:


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.



来源:https://stackoverflow.com/questions/30644997/mkmapsnapshotter-completionhandler-never-called-in-parent-app-when-called-from-w

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