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?
The watchdog timer is disabled when running from Xcode.
I mostly get sensible values (ie. 600) when running unconnected, but I still get the occasional weird value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With