3
我在我的iPhone應用程序中使用地理位置。即使我已經使用了幾秒鐘的地理位置,或者應用程序在後臺,電池電量也會更快耗盡。iOS:如何檢查地理位置是否仍然打開?
如何檢查地理位置服務是否仍在我的iPhone設備上打開?這是我所使用的代碼:
...
locationManager = [[CLLocationManager alloc] init]; // Create new instance of locMgr
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
NSLog(@"locationManager startUpdatingLocation");
reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:locationManager.location.coordinate];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
...
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSLog(@"reverseGeocoder failed: %@", [error localizedDescription]);
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
NSLog(@"locality %@", placemark.locality);
location = [placemark.locality retain];
}