简体   繁体   English

3分钟后iOS 9位置更新后台任务

[英]iOS 9 Location Update Background task after 3 minutes

I've been digging into this code which is using a basic timer to check for location updates. 我一直在深入研究这个使用基本计时器检查位置更新的代码。 I then have it sending lat/lng to a server. 然后我将它发送到服务器的lat / lng。

http://mobileoop.com/background-location-update-programming-for-ios-7 https://github.com/voyage11/Location http://mobileoop.com/background-location-update-programming-for-ios-7 https://github.com/voyage11/Location

It's working well when plugged in and hooked up through XCode, however when I unplug and take the device mobile, the OS seems to always kill the background thread exactly after 3 minutes. 当插入并通过XCode连接时,它运行良好,但是当我拔下并移动设备时,操作系统似乎总是在3分钟后完全杀死后台线程。 So if I set the timer to run every 30 seconds, I'll get ~6 updates until I bring the app up to the foreground. 因此,如果我将计时器设置为每30秒运行一次,我将获得~6次更新,直到我将应用程序带到前台。

I have read that max background execution time is 3 minutes, but as I see it this code is resetting the background task after 1 minute, so I'm not sure why I'm seeing this. 我已经读过最大后台执行时间是3分钟,但是我看到这个代码在1分钟后重置了后台任务,所以我不知道为什么我会看到这个。

There must be some way around this. 必须有一些解决方法。 Anything I can do here? 我能在这做什么吗?

EDIT: this helped me: allowsBackgroundLocationUpdates in CLLocationManager in iOS9 编辑:这帮助我: 在iOS9中的CLLocationManager中的allowsBackgroundLocationUpdates

se: SE:

if ([self.locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
    [self.locationManager setAllowsBackgroundLocationUpdates:YES];
}

This is needed for background location tracking. 这是后台位置跟踪所必需的。

如果其他人遇到这个问题,上面列出的github仓库中的代码 - https://github.com/voyage11/Location-最近已经更新了iOS 9的修复程序,这将允许GPS连续轮询没有线程的背景在3分钟后终止。

In case anyone runs into unreliablity problems when running this otherwise excellent library, integrated into other xcode modules in a more sophisticated app, they might look at the initialisation statement for the background task list Id array and consider changing _bgTaskIdList = [NSMutableArray array]; to _bgTaskIdList = [[NSMutableArray alloc]init]; in BackgroundTaskManager.m 如果任何人在运行这个非常优秀的库时遇到不可靠的问题,在更复杂的应用程序中集成到其他xcode模块中,他们可能会查看后台任务列表Id数组的初始化语句,并考虑更改_bgTaskIdList = [NSMutableArray array]; to _bgTaskIdList = [[NSMutableArray alloc]init]; in BackgroundTaskManager.m _bgTaskIdList = [NSMutableArray array]; to _bgTaskIdList = [[NSMutableArray alloc]init]; in BackgroundTaskManager.m _bgTaskIdList = [NSMutableArray array]; to _bgTaskIdList = [[NSMutableArray alloc]init]; in BackgroundTaskManager.m Until I did this I got unreliable behavious. _bgTaskIdList = [NSMutableArray array]; to _bgTaskIdList = [[NSMutableArray alloc]init]; in BackgroundTaskManager.m直到我这样做,我的行为不可靠。 Sometimes it worked and sometimes I got a stack dump. 有时它工作,有时我得到一个堆栈转储。 I found that this was because bgTaskList had been overwritten with other data causing bad access errors. 我发现这是因为bgTaskList已被其他数据覆盖,导致错误的访问错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM