I'm trying to check the value of backgroundTimeRemaining
, but I get a very large number. The value of the property is supposed to be the corresponding to 10 min aprox, and I`ve read in Apple documentation here that such value is large when the app is in the foreground. However, I get a large value even when in background:
- (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];
}
}
What could am I missing?
applicationDidEnterBackground
event has been handled completely. – ItabackgroundTimeRemaining
value? – Burden