我在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