从 WatchKit 调用时,MKMapSnapshotter completionHandler 从未在父应用程序中调用
MKMapSnapshotter completionHandler never called in parent app when called from WatchKit
我有这个奇怪的问题:
我像往常一样用 openParentApplication:reply:
调用父应用程序。
它使用异步 NSURLRequests
从互联网获取一些数据做得很好,但是当我想使用 MKMapSnapshotter
获取地图图像时(仍在父应用程序中),它的完成块是从来没有打电话。
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
NSLog(@"completion handler is called"); //this never called
};
我尝试通过 snapshotter startWithQueue:
on dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)
或 dispatch_get_main_queue()
等方式拨打电话,但似乎没有任何效果。
如果我直接从 WKInterfaceController
或父应用程序调用相同的代码,它就可以正常工作。
我不认为你可以 call/use MKMapSnapshooter
你想要的方式。当您使用 openParentApplication
发出请求时,它会在后台模式下打开您的父应用程序,并且 MKMapSnapshooter
需要前台模式才能提供最终图像。
根据 Apple 文档:
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.
我有这个奇怪的问题:
我像往常一样用 openParentApplication:reply:
调用父应用程序。
它使用异步 NSURLRequests
从互联网获取一些数据做得很好,但是当我想使用 MKMapSnapshotter
获取地图图像时(仍在父应用程序中),它的完成块是从来没有打电话。
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
NSLog(@"completion handler is called"); //this never called
};
我尝试通过 snapshotter startWithQueue:
on dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)
或 dispatch_get_main_queue()
等方式拨打电话,但似乎没有任何效果。
如果我直接从 WKInterfaceController
或父应用程序调用相同的代码,它就可以正常工作。
我不认为你可以 call/use MKMapSnapshooter
你想要的方式。当您使用 openParentApplication
发出请求时,它会在后台模式下打开您的父应用程序,并且 MKMapSnapshooter
需要前台模式才能提供最终图像。
根据 Apple 文档:
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.