以下是一些简单的代码:
// 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
的调用...我只是试图获取用户的当前位置(不使用地图)。任何想法或想法将不胜感激。
答案 0 :(得分:5)