How to implement Task completion

Task completion — applications can ask the system for extra time to complete a given task.

I am using this method for Task Completion,

  • How to Merge PDF file with Annotation
  • iOS browser - iFrame jumps to top when changing css or content using javascript
  • Swift accessing and updating tableview in container view
  • Autolayout height equal to MAX(multiple view heights)
  • How to implement a “rate us” feature in a phonegap app
  • sqlite Convert Text to Numbers
  • - (void)applicationDidEnterBackground:(UIApplication *)application 
        UIApplication  *app = [UIApplication sharedApplication];
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^
             NSLog(@"This is Testing");
            [app endBackgroundTask:bgTask]; 

    But i am not getting any output from this method. Anyone tell me, what i am doing wrong.Can you tell any best method to implement for the task completion.



    2 Solutions Collect From Internet About “How to implement Task completion”

    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!