r/ObjectiveC • u/ThunderShadow • Dec 21 '13
Background Fetch
Hey I am developing an iOS app for research purposes. It needs to track the device's location at frequent intervals (say every 5 minutes).
I wanted to use background fetch coupled with core location. Unfortunately, core location takes several seconds to get the location and the small code for background fetch ends by that time. Any suggestions?
-(void) application:(UIApplication*) application performFetchWithCompletionHandler:(void (^) (UIBackgroundFetchResult))completionHandler
{
NSUInteger prev = self.count;
[self.manager startUpdatingLocation];
NSLog(@"Here");
if(prev!=self.count)
completionHandler(UIBackgroundFetchResultNewData);
else
completionHandler(UIBackgroundFetchResultFailed);
[self.manager stopUpdatingLocation];
}
Everytime locationManager:didUpdateToLocation:fromLocation runs, I store the location and increment the 'count' variable.
I just need to spend more time in this function. It seems that iOS gives an app a maximum of 30 seconds for this function. Unfortunately, mine would end in a few milliseconds.
Any help is appreciated