【发布时间】:2016-04-13 10:02:59
【问题描述】:
我在我的应用程序中使用CLLocationManager 并将pausesLocationUpdatesAutomatically 属性设置为YES 以节省电池。当位置暂停时,然后我尝试使用startUpdatingLocation 方法在指定的时间间隔后重新启动位置更新,它启动并给出7 到 10 次位置更新。之后我没有得到任何进一步的位置更新。我调用下面的方法重新开始更新。
PS:我已经在功能中启用了位置背景模式。
[_locManager startUpdatingLocation];
if ([_locManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)])
{
_locManager.allowsBackgroundLocationUpdates =YES;
}
【问题讨论】:
-
@kb920 请再次阅读我的问题。我已经将此属性设置为 YES。
-
你使用
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{ }delegate 方法对吗? -
@Vvk yes didUpdateLocations 正在使用中。
-
一一尝试两种方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { } -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { } -
我知道的唯一解决方法(我从副本中找到)是在前台调用
startMonitoringSignificantLocationChanges。如果您这样做,那么您似乎可以在后台调用 `startUpdatingLocations 并无限期地获取更新
标签: ios objective-c xcode cllocationmanager background-process