iOS MKMapShapshotter完成块并不总是被调用 [英] iOS MKMapShapshotter completion block is not always being called

查看:170
本文介绍了iOS MKMapShapshotter完成块并不总是被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use the new iOS7 MKMapSnapshotter to generate a static map image. Whenever my app needs a map, I call the following:

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;
}

在大多数情况下,这很有效。但有时,似乎设备因地图请求而过载,然后停止渲染。在我的日志文件中,我将看到关于已分配的Snapshotter的第一个日志语句,但从未看到Snapshotter完成块消息。

In most cases this is working great. However sometimes, it seems like the device gets overloaded with requests for maps and then it stops rendering. In my log file I will see the first log statement about the "Snapshotter allocated" but never see the "Snapshotter completion block" message.

我的请求是否可能是从未执行过调度队列?
有没有人遇到过这个问题?

Is it possible that my requests are never executed off of the dispatch queue? Has anyone ever had this problem?

推荐答案

这是(或似乎是)MKMapSnapshotter中的一个错误。

This is (or appears to be) a bug in MKMapSnapshotter.

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

If network data and WiFi are turned off, the completion handler will not be called (unless there are cached data in the OS - see https://stackoverflow.com/a/5769108/481207 for clearing the cache).

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

In fact, the snapshotter appears to block waiting on data. It does not time out or detect that there is no data. After many minutes, e.g. 15 minutes, snapshotter.isLoading = YES. Calling cancel does not cause the completion handler to be called.

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

If WiFi or network data are turned back on, subsequent calls to start a (new) snapshotter will call the completion handler.

如果在处理程序中启动并清除快照程序时设置了变量,则此s *会很严重,因为变量永远不会被清除。

This s*cks badly if a variable is set when the snapshotter is started and cleared in the handler, because the variable is never cleared.

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 MKMapShapshotter完成块并不总是被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆