我在CLLocationManager回调中遇到了一些问题
等待异步回调的最佳方式是什么?等待异步回调 - Objective-C
这里是我基本上要做到:
- (NSString *)getCurrentCity { [self.locationManager startUpdatingLocation]; // Wait for coordonate in callbacks self.geocoder = [MKReverseGeocoder alloc] initWithCoordonate:self.newCoordonate]; [self.geocoder start]; // Wait for information with MKReverse callbacks return self.currentCity; } // Callbacks methods of MKReverseGeocoder and 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是我CLASSE的attribut。
我尝试了一些技巧,如线程和/或同步,但我没有管理它在所有完成之前不返回。
问候
self.currentCoordonate =&newCoordonate;这让我害怕了很多级别 – 2010-11-16 16:26:25
异步回调的重点在于您无需等待。 – koo 2010-11-16 17:18:17