gpt4 book ai didi

iOS MKMapSnapshotter 完成 block 并不总是被调用

转载 作者:技术小花猫 更新时间:2023-10-29 11:07:35 26 4
gpt4 key购买 nike

我正在尝试使用新的 iOS7 MKMapSnapshotter 生成静态 map 图像。每当我的应用程序需要 map 时,我都会调用以下命令:

MKMapSnapshotter *snapshotter = [[[MKMapSnapshotter alloc] initWithOptions:theOptions] autorelease];
dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
DebugLog(@"Snapshotter allocated %@ and run on queue %@", snapshotter, aQueue);

[snapshotter startWithQueue:aQueue completionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
DebugLog(@"Snapshotter completion block %@", snapshotter);
// perform selector on main thread to set self.imageView.image = shanpshot.image;
}

在大多数情况下,这很有效。但是有时,设备似乎因 map 请求而过载,然后停止渲染。在我的日志文件中,我将看到关于“已分配快照程序”的第一条日志语句,但从未看到“快照程序完成 block ”消息。

有没有可能我的请求永远不会离开调度队列执行?有没有人遇到过这个问题?

最佳答案

这是(或看起来是)MKMapSnapshotter 中的错误。

如果关闭网络数据和 WiFi,将不会调用完成处理程序(除非操作系统中有缓存数据 - 请参阅 https://stackoverflow.com/a/5769108/481207 以清除缓存)。

事实上,快照程序似乎会阻止等待数据。它不会超时或检测到没有数据。几分钟后,例如15 分钟,snapshotter.isLoading = YES。调用 cancel 不会导致调用完成处理程序。

如果 WiFi 或网络数据重新打开,启动(新)快照器的后续调用将调用完成处理程序。

如果在快照程序启动时设置变量并在处理程序中清除,这会很糟糕,因为变量永远不会被清除。

if (!isRendering) {
isRendering = YES;

[snapshotter startWithCompletionHandler:
^(MKMapSnapshot* snapshot, NSError* error) {
// This may not be called so this code will
// never run again.
isRendering = NO;
}];
}

关于iOS MKMapSnapshotter 完成 block 并不总是被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22774090/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com