I am trying to check the value of backgroundTimeRemaining , but I am getting a very large number. The value of the property should correspond to the 10-minute aprox, and I read in the Apple documentation here that such a value is great when the application is in the foreground. However, I get a lot of value even in the 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 can I lose? thanks in advance
source share