Task completion — applications can ask the system for extra time to complete a given task.
I am using this method for Task Completion,
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^
{
NSLog(@"This is Testing");
[app endBackgroundTask:bgTask];
bgTask=UIBackgroundTaskInvalid;
}];
}
But i am not getting any output from this method. Anyone tell me, what i am doing wrong.Can开发者_Go百科 you tell any best method to implement for the task completion.
Regards,
Arunkumar.P
You are setting up an expiration handler, but you don't appear to be actually doing anything in the background. It looks like the code you have above is copied from the Executing Code in the Background section of the iOS app programming guide. The next piece of code in that exxample is:
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
The expiration handler won't be called until the time limit (10 minutes, last time I checked) is reached; you do the work in the task that you dispatch asynchronously, not in the expiration handler.
This solved my problem: Easy Background Tasks In IOS 4.
The main idea is to dispatch an async execution code that does nothing, but allows your current code to keep running.
Hope it solves yours too!
精彩评论