问题
Even my app is register for Location updates in background.
In my code:
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
self.locationManager.distanceFilter = 2500;
And I not moved anywhere. So after exactly 15 minutes in console log I got this message "Location icon should now be in state 'Inactive'" . From this point onwards my app is not running in background.
It's happening in iPhone 5 only.
@updated
Here is my code
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager setPurpose:@"Enable Location service for \"My App\" to track your"];
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
/* Notify changes when device has moved x meters.
* Default value is kCLDistanceFilterNone: all movements are reported.
*/
self.locationManager.distanceFilter = 2500;
[self.locationManager startUpdatingLocation];
回答1:
Was your app in the background when location service become inactive?
If you don't want to pause location update in background than you need to set pausesLocationUpdatesAutomatically flag,
if ([self.locationManager respondsToSelector:@selector(pausesLocationUpdatesAutomatically)]) {
self.locationManager.pausesLocationUpdatesAutomatically = NO;
}
回答2:
Since iOS 6 Apple has added @property(assign, nonatomic) BOOL pausesLocationUpdatesAutomatically to CLLocationManager. Default value is YES. Change value of this property to NO and the location tracking will not stop in the background.
来源:https://stackoverflow.com/questions/19561355/location-service-going-to-inactive-state-in-iphone-5