我正在尝试检查 的值backgroundTimeRemaining
,但我得到了一个非常大的数字。该属性的值应该对应于大约 10 分钟,我在 Apple 文档中读到,当应用程序处于前台时,这个值很大。但是,即使在后台,我也能获得很大的价值:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Background task
NSTimeInterval timeRemaining = [UIApplication sharedApplication].backgroundTimeRemaining;
NSLog(@"Background time remaining: %f seconds (%d mins)", timeRemaining, (int)(timeRemaining / 60));
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSTimeInterval timeRemaining = [UIApplication sharedApplication].backgroundTimeRemaining;
NSLog(@"Background time remaining: %f seconds (%d mins)", timeRemaining, (int)(timeRemaining / 60));
// Perform task
// Finished
if (bgTask != UIBackgroundTaskInvalid) {
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
});
// Start location manager
if ([CLLocationManager locationServicesEnabled]) {
[locationManager startUpdatingLocation];
}
}
我能错过什么?