Location service going to “Inactive” state in iPhone 5

一笑奈何 提交于 2019-12-01 07:32:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!