【发布时间】:2011-05-10 22:16:43
【问题描述】:
我在使用 CLLocationManager 回调时遇到了一些问题
等待异步回调的最佳方式是什么?
这是我基本上想做的事情:
- (NSString *)getCurrentCity { [self.locationManager startUpdatingLocation]; // 等待回调中的坐标 self.geocoder = [MKReverseGeocoder alloc] initWithCoordonate:self.newCoordonate]; [self.geocoder 开始]; // 使用 MKReverse 回调等待信息 返回 self.currentCity; } // MKReverseGeocoder 和 CLLocationManager 的回调方法 - (void)locationManager:(CLLocationManager *)manager idUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { CLLocationCoordinate2D newCoordonate = newLocation.coordinate; self.currentCoordonate = &newCoordonate; } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { self.currentCity = placemark.locality; }self.currentCity 和 self.newCoordonate 是我班级的一个属性。
我尝试了一些技巧,例如线程和/或同步,但我没有设法让它在一切完成之前不返回。
最好的问候
【问题讨论】:
-
self.currentCoordonate = &newCoordonate;这让我在很多层面上都感到害怕
-
异步回调的全部意义在于您不必等待它。
标签: objective-c multithreading callback