Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get CLLocationManager to stop tracking
    primarykey
    data
    text
    <p>I have a class that launches an instance of CLLocationManager. The intent is to use it to get a decent, one-time fix on app launch and then stop location services for the duration (or until some other condition is met which requires a new fix...but that part isn't yet written).</p> <p>For some reason, even though I call [stopUpdatingLocation], my app still seems to be keeping location services active indefinitely, whether in the background or not. My delegate doesn't receive updates anymore, as expected, but the arrow stays on the status bar. I turned off location services for all other apps to verify that mine was the culprit, and then killed my app manually (which immediately dismissed the arrow).</p> <p>My code is based on what you find in the Apple docs, with some things added for my purposes. I've read through all the pertinent Apple docs and just can't figure out what I'm doing wrong. All the other answers on the subject address people who are using MKMapView and forget to set "showUserLocation" to NO...I'm not using an MKMapView at all, so that's not my issue. What the heck. Why won't it die?</p> <p>(_locationManager is, of course my instance of CLLocationManager).</p> <pre><code>- (void)locationManager:(CLLocationManager *)manager didUpdateLocations: (NSArray*)locations { CLLocation* lastLocation = [locations lastObject]; // Ignore old (cached) location NSDate *date = lastLocation.timestamp; NSTimeInterval howRecent = [date timeIntervalSinceNow]; if (abs(howRecent) &gt; 30.0) { DLog(@"Ignoring cached fix"); return; } // Wait for better fix if we have GPS if (lastLocation.horizontalAccuracy &gt; 60 &amp;&amp; _GPSEnabled) { DLog(@"Ignoring inaccurate fix on GPS-enabled device"); return; } // Accept mediocre fix if we don't have GPS if (lastLocation.horizontalAccuracy &lt; 300 &amp;&amp; _GPSEnabled == NO) { _hasPos = YES; _lastPos = lastLocation.coordinate; DLog(@"Best fix we're likely to get without GPS: %f %f", _lastPos.latitude, _lastPos.longitude); [self stopTracking]; return; } // If we have GPS, accept a fix with &lt;60m accuracy _hasPos = YES; _lastPos = lastLocation.coordinate; DLog(@"Geolocator has good fix: %f %f", _lastPos.latitude, _lastPos.longitude); [self stopTracking]; } -(void)stopTracking { DLog(@"Stopped updating locations"); [_locationManager stopUpdatingLocation]; _locationManager.delegate = nil; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload