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 do multithreading, concurrency or parallelism in iOS Swift?
  • iOS Multi-Tasking Track GPS Location
  • Quit app when pressing home
  • Sprite Kit & playing sound leads to app termination
  • How to use AVCaptureSession with Slide Over and Split View in iOS 9?
  • background audio recording in iOS
  • - (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!