Here is some simple code:
// ViewControllerA.m
-(void) viewDidLoad
{
[super viewDidLoad];
self.networkMonitor = [[NetworkMonitor alloc] init];
...
[self.networkMonitor.locationManager startUpdatingLocation];
...
}
in network monitor:
// 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]);
}
I’ve called startUpdatingLocation, NetworkMonitor implements CLLocationManagerDelegate…why am I not getting any calls to didUpdateLocations? Am I misunderstanding when this method should get called? I assume that once startUpdatingLocation is called, I should receive at least one call to didUpdateLocations… I’m simply trying to get the user’s current location (without using a map). Any ideas or thoughts would be much appreciated.
are you building for ios6? from docs: In iOS 5 and earlier, the location manager calls the locationManager:didUpdateToLocation:fromLocation: method instead.