我的应用程序需要在后台跟踪用户位置变化,并且只要用户四处移动就可以正常工作。
当用户停止并且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{}
Why is 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];
如果您搜索pausesLocationUpdatesAutomatically
在 Apple 论坛上,您会发现最近有一个类似的问题,该问题已得到 Apple 开发人员的回应。我不会在这里直接重新发布它,因为它是一个私人论坛,但要点是位置暂停是在用户forgets他们已经运行了一个位置感知应用程序并已停止使用它。通过暂停更新,他们的电池不会很快耗尽。不幸的是,无法知道新的动作是恢复活动还是做其他事情,因此更新不会恢复,直到应用程序返回前台。他们的建议是catch暂停呼叫并以某种方式引起用户的注意,让他们在仍然需要更新时打开应用程序。
EDIT:
来自Apple自己的文档暂停位置自动更新 https://developer.apple.com/documentation/corelocation/cllocationmanager/1620553-pauseslocationupdatesautomatical。他们建议:
发生暂停后,your当您确定需要定位服务时,有责任再次重新启动定位服务。核心位置称为locationManagerDidPauseLocationUpdates(_:) https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate/1621553-locationmanagerdidpauselocationu您的位置经理的代表的方法让您知道
发生暂停。在该方法中,您可以配置本地
触发器类型为的通知UNLocationNotificationTrigger https://developer.apple.com/documentation/usernotifications/unlocationnotificationtrigger并设置为当用户退出当前区域时发出通知。这
本地通知消息应提示用户启动
再次您的应用程序,以便它可以恢复更新。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)