我正在尝试实施这篇文章中给出的建议.
不幸的是,我不清楚这些步骤.我尝试实现这些建议,但是即使在我启动和停止locationServices之后,backgroundTimeRemaining仍然继续减少.这就是我开发它的方式:
- (void)applicationDidEnterBackground:(UIApplication *)application {
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
self.timer = nil;
[self initTimer];
});
}
Run Code Online (Sandbox Code Playgroud)
initTimer:
- (void)initTimer {
// Create the location manager if this object does not
// already have one.
if (nil == self.locationManager)
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager …Run Code Online (Sandbox Code Playgroud)