简体   繁体   English

强制CLGeocoder块代码同步运行

[英]Forcing CLGeocoder block code to run synchroniously

I use CLGeocoder to geocode a list of addresses so that certain kinds of information can be shown to the user in a UITableView . 我使用CLGeocoder对地址列表进行地理编码,以便可以在UITableView中向用户显示某些类型的信息。 However, all of the CLGeocoder geocoding and reverse geocoding methods take as a parameter a block of code that is run asynchronously from the rest of the program whenever the geocoding request is complete: 但是,所有CLGeocoder地理编码和反向地理编码方法都将一个代码块作为参数,只要地理编码请求完成,该代码块就会与程序的其余部分异步运行:

- (void)geocodeAddressString:(NSString *)addressString 
completionHandler:(CLGeocodeCompletionHandler)completionHandler

Is there a way to force this code to run synchronously (ie force the program to wait for the geocoding request to complete and wait for it to be processed by the handler before moving on) . 有没有一种方法可以强制此代码同步运行(即,强制程序等待地理编码请求完成并等待处理程序对其进行处理再继续)

No, there isn't. 不,没有。 And if there were, it would be a very bad idea (at least if you ran this asynchronously on the main thread). 如果有的话,那将是一个非常糟糕的主意(至少如果您在主线程上异步运行了此主意)。 You have no control over how long the geocoding process would take (could be dozens of seconds in case of a server timeout) and if it took longer than about 5 seconds, the OS's watchdog timer would immediately kill your app because it no longer responds. 您无法控制地理编码过程将花费多长时间(如果服务器超时,可能需要数十秒),并且如果花费的时间超过大约5秒,则操作系统的看门狗计时器将立即终止您的应用程序,因为它不再响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM