【发布时间】:2013-07-03 06:56:43
【问题描述】:
我的应用程序需要在后台跟踪用户位置的变化,并且只要用户四处走动就可以正常工作。
当用户停止并且CLLocationManager 在 10-20 分钟左右后暂停时。此通知表明:
-(void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager{}
这对我来说也很好。太好了,我节省了一些电池等。
问题是CLLocationManager 永远不会在用户再次开始移动时唤醒,并且遵循在我将应用程序置于前台之前永远不会触发委托方法(激活):
//Never called back after CLLocationManager pauses:
-(void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager{}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{}
为什么在设备再次开始移动后从未调用过locationManagerDidResumeLocationUpdates? GPS不应该也自动恢复(因为自动暂停)?
有没有办法在没有用户交互的情况下恢复 GPS?
应用程序在 Info.plist 文件中声明了以下内容:
我的 CLLocationManager 设置是:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setActivityType:CLActivityTypeFitness];
//I WANT pauses to save some battery, etc... That is why following line is commented out (default)
//[locationManager setPausesLocationUpdatesAutomatically:NO];
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
【问题讨论】:
-
返回前台时,是否收到自gps投递关闭以来的所有位置事件,还是全部丢失?
-
是的,当我返回前台时,所有位置更新都会重新开始。
-
问题是,如果您同时获得背景和前景之间的位置。 (你会得到一个位置列表)
-
这不是解决方案。我想停下来工作。文档指出,当用户再次开始移动时,应该调用 resume。我想知道为什么没有。
-
我的问题不是关于 pausesLocationUpdatesAutomatically 属性的作用。我理解这个功能。我的问题主要是关于恢复 GPS。我需要确切知道暂停是否确定,或者 GPS 是否可以自动恢复。当我结束对此的研究并证明你是对的时,我当然会接受答案。
标签: ios objective-c core-location cllocationmanager uiapplicationdelegate