从WatchKit调用MKMapSnapshotter completionHandler在父应用程序中从不调用

我有这个奇怪的问题:我打电话给父应用程序openParentApplication:reply:正常。

使用asynchronousNSURLRequests从网上获取一些数据是非常NSURLRequests但是当我想使用MKMapSnapshotter (仍然在父应用程序中)获取地图图像时,它的完成块永远不会被调用。

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

我试着用: snapshotter startWithQueue:调用snapshotter startWithQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)dispatch_get_main_queue()等,但似乎没有任何工作。

如果我直接从WKInterfaceController或从父应用程序调用相同的代码,它工作得很好。

我不认为你可以调用/使用MKMapSnapshooter你想要的方式。 当您使用openParentApplication进行请求时,它将在后台模式下打开您的父应用程序,而MKMapSnapshooter需要Foreground模式才能提供最终的图像。

按照苹果文档:

只有当它在前台运行时,快照程序才会将最终图像传送到您的应用程序。 当您的应用程序处于前台时,快照程序必须呈现最终图像。 如果您在应用程序处于后台时开始生成快照,或者在快照正在进行时应用程序移至后台,则此行为会延迟快照的传递,直到您的应用程序返回到前台。