为什么不调用locationManager:didUpdateLocations?

时间:2012-10-23 19:30:54

标签: iphone ios gps core-location cllocationmanager

以下是一些简单的代码:

// 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的调用...我只是试图获取用户的当前位置(不使用地图)。任何想法或想法将不胜感激。

1 个答案:

答案 0 :(得分:5)

你正在为ios6建造吗?来自docs:在iOS 5及更早版本中,位置管理器调用locationManager:didUpdateToLocation:fromLocation:方法。