How to implement Task completion

前端 未结 2 1539
失恋的感觉
失恋的感觉 2020-12-22 11:22

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

I am using this method for Task Completion,

- (void)applic         


        
相关标签:
2条回答
  • 2020-12-22 12:02

    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.

    0 讨论(0)
  • 2020-12-22 12:18

    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!

    0 讨论(0)
提交回复
热议问题