我使用 locationmanger 来获取我在 iPhone 上的当前位置。
#pragma mark - Location handling
-(void)doLocation {
self.locationManager = [[CLLocationManager alloc] init];
[...]
SingletonClass *sharedSingleton = [SingletonClass sharedInstance];
sharedSingleton.coordinate = [location coordinate];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[...]
SingletonClass *sharedSingleton = [SingletonClass sharedInstance];
[sharedSingleton setCoordinate:CLLocationCoordinate2DMake(currentLat, currentLng)];
NSLog(@"debug: self.currentLoc: %@", self.currentLoc);
}
这很好用,我得到了一些延迟的位置坐标,并且可以通过 sharedSingleton 访问它们。当我有坐标时,我必须触发另一个需要坐标作为参数的函数。
我的问题从这里开始......
我现在该怎么办,当检索到坐标时,我可以调用需要坐标作为输入参数的其他函数。有没有我可以使用的观察者?如果,我该如何实施?
我只需要一些告诉我的东西:嘿,伙计,坐标可以使用了,这样我就可以触发下一个功能了..