In my app with Asynchronous downloads, I am trying to implement multitasking to allow background tasks to complete, but am getting errors. In the AppDelegate didEnterBackground:
I start a download, and then click the home button. The download doesn't terminate, but it doesn't keep going. Once I go back to the app it resumes. Then, when the app is finished: if it was sent to background at any point during the download, I get the following error in Console:
If I allow the download to finish without ever entering background, all is fine.
Code:
application = [UIApplication sharedApplication]; //Get the shared application instance
__block UIBackgroundTaskIdentifier background_task; //Create a task object
background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {
[application endBackgroundTask: background_task]; //Tell the system that we are done with the tasks
background_task = UIBackgroundTaskInvalid; //Set the task to be invalid
//System will be shutting down the app at any point in time now
}];
//Background tasks require you to use asyncrous tasks
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//Perform your tasks that your application requires
NSLog(@"\n\nRunning in the background!\n\n");
[application endBackgroundTask: background_task]; //End the task so the system knows that you are done with what you need to perform
background_task = UIBackgroundTaskInvalid; //Invalidate the background_task
});
Code:
2012-03-13 12:17:25.981 SMCoC[16086:17f03] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x10ce80f0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key response.'
*** First throw call stack:
Last edited: