Luk*_*asz 29 objective-c core-location uiapplicationdelegate cllocationmanager ios
我的应用程序需要在后台跟踪用户位置更改,并且只要用户移动就可以正常工作.当用户CLLocationManager在10-20分钟左右停止并暂停时.此通知表明:
-(void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager{}
Run Code Online (Sandbox Code Playgroud)
这对我也没关系.太棒了,我节省了一些电池等
问题是CLLocationManager当用户再次开始移动时永远不会醒来,并且在我将应用程序放到前台之前永远不会触发委托方法(获取活动):
//Never called back after CLLocationManager pauses:
-(void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager{}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{}
Run Code Online (Sandbox Code Playgroud)
为什么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];
Run Code Online (Sandbox Code Playgroud)
小智 31
如果您pausesLocationUpdatesAutomatically在Apple论坛上搜索,您会发现一个类似行的最近一个问题,该问题得到了Apple开发人员的回复.我不会直接在这里重新发布它,因为它是一个私人论坛,但要点是,当用户忘记他们已经有一个位置感知应用正在运行并且已经停止使用它时,该位置暂停.通过暂停更新,他们的电池不会快速耗尽.不幸的是,不可能知道新的移动是他们恢复活动还是做其他事情,所以在应用程序回到前台之前不会恢复更新.他们的建议是抓住暂停电话并以某种方式引起用户的注意,让他们打开应用程序,如果他们仍然想要更新.
编辑:
从Apple自己的pausesLocationUpdates文档中自动获取.他们建议:
暂停发生后,当您确定需要时,您有责任再次重新启动位置服务.核心位置调用
locationManagerDidPauseLocationUpdates(_:)您的位置管理员委托的方法,以通知您已发生暂停.在该方法中,您可以配置其触发器类型的本地通知,UNLocationNotificationTrigger并设置为在用户退出当前区域时通知.本地通知的消息应提示用户再次启动您的应用程序,以便它可以恢复更新.
| 归档时间: |
|
| 查看次数: |
9324 次 |
| 最近记录: |