Does anyone know how to turn off iPhone's GPS programmatically? Once I use the CLLocationManager to get three reads of my location I stop updating location as in the code below:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
if((newLocation.horizontalAccuracy > 0.0f) &&
(newLocation.horizontalAccuracy < 7000.0f) ){
if(self.locations.count > 3){
[self.locationManager stopUpdatingLocation];
}
[self.locations addObject:newLocation];
}
But this still seems to leave the GPS on while users are using my app and draining their battery. All I need to do is read the location three times so that I can get an accurate read, and then shut down the GPS. Does anybody know how to shut down the GPS with objective-C?
stopUpdatingLocation give the location manager the option to shutdown the hardware, but it is not guaranteed. It is supposed to shut down the hardware when no one else needs it. In practice, it seems to work as one would expect.
Is it possible stopUpdatingLocation just never gets called? In your snippet above, it does not look to be unreasonable that your code never makes it to that call.
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