这是一些简单的代码:
// ViewControllerA.m
-(void) viewDidLoad
{
[super viewDidLoad];
self.networkMonitor = [[NetworkMonitor alloc] init];
...
[self.networkMonitor.locationManager startUpdatingLocation];
...
}
在网络监视器中:
// NetworkMonitor.m
-(id) init
{
self = [super init];
if (self != nil) {
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager setDelegate:self];
}
return self;
}
...
// this is never called!
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"%s, location manager returned a new location.", __FUNCTION__);
...
}
// and neither is this
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Error: %@", [error description]);
}
我调用了 startUpdatingLocation,NetworkMonitor 实现了 CLLocationManagerDelegate...为什么我没有接到任何对 didUpdateLocations 的调用?我是否误解了何时应该调用此方法?我假设一旦startUpdatingLocation
被调用,我应该至少接到一个电话didUpdateLocations
......我只是想获取用户的当前位置(不使用地图)。任何想法或想法将不胜感激。