I am just trying to test an idea for a background task, but I can't get my test app to do anything in the background.
I have a button to start the task. Here is the code I have:
While I am in the app the code executes, but as soon as I leave the app it stops. I checked the background time remaining as you see above and in the
applicationDidEnterBackground:. The one above returns a huge number because it is still in the app. But the other one only returns 9.898437. But even then the task doesn't run for even 9 seconds. It terminates immediately.
Also I have another question. Will an app log to the the console while it is running in the background? Just in case it doesn't I set it to log (after returning to the foreground) how much progress it made while in the background. It returns no progress made.
It compiles successfully without any warnings. What am I doing wrong? Any suggestions?
I have a button to start the task. Here is the code I have:
Code:
- (IBAction) startTask: (id) sender
{
UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^(void){}];
[self startBackgroundTask];
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
NSLog(@"backgroundTimeRemaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]);
}
While I am in the app the code executes, but as soon as I leave the app it stops. I checked the background time remaining as you see above and in the
applicationDidEnterBackground:. The one above returns a huge number because it is still in the app. But the other one only returns 9.898437. But even then the task doesn't run for even 9 seconds. It terminates immediately.
Also I have another question. Will an app log to the the console while it is running in the background? Just in case it doesn't I set it to log (after returning to the foreground) how much progress it made while in the background. It returns no progress made.
It compiles successfully without any warnings. What am I doing wrong? Any suggestions?