简体   繁体   中英

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.

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. 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.

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.

There must be some way around this. Anything I can do here?

EDIT: this helped me: allowsBackgroundLocationUpdates in CLLocationManager in iOS9

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 _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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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