Basically half the time the delegate method
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
is not called at all. But the other half of the time it works perfectly! I've found that it usually happens when I first start up Xcode after closing and quitting it, but then after that or a couple runs after that it seems to work fine. I'm not 100% sure if it's just an Xcode problem or what, I'll be getting a developer's license soon so I'll see if it will work fine on an actual device.
Starting from the viewDidAppear (tried in viewDidLoad also, made no difference), I run a method to init my locationManager stuff:
locationManager = [[CLLocationManager alloc]init];
[locationManager setDelegate:self];
locationManager.distanceFilter = 20.0f;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.pausesLocationUpdatesAutomatically = NO;
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
Sometimes this works, sometimes it doesn't. I even made a timer to re-run this every so-and-so seconds, and this doesn't work.
Is there something else I should do? Is there any answer to this problem?
Thanks.
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
This delegate method is invoked only if new locations are available. Sometimes gps will not get satellite signal hence locations cannot be obtained. So in these situations the above mentioned method will not get triggered. Since you are testing in simulator,you should change or set the location. I think it will work fine on an actual device.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With