How to implement task completion

Task completion - applications may request additional time from the system to complete a given task.

I use this method to complete the task,

- (void)applicationDidEnterBackground:(UIApplication *)application { UIApplication *app = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^ { NSLog(@"This is Testing"); [app endBackgroundTask:bgTask]; bgTask=UIBackgroundTaskInvalid; }]; } 

But I do not get any result from this method. Someone will tell me what I'm doing wrong. You can tell what is the best way to implement to complete the task.

Hello,

Arunkumar.P

0
source share
2 answers

You set up an expiration handler, but you don't seem to be doing anything in the background. It looks like the code you specified above is copied from the Running Code in the Background section of the iOS Application Programming Guide. The following code snippet in this example:

 // 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 will not be called until the expiration is reached (10 minutes, the last time I checked); you are doing work in a task that you submit asynchronously, and not in an expiration handler.

+1
source

This solved my problem: Light background tasks in iOS 4 .

The basic idea is to send async executable code that does nothing but allow your current code to continue to work.

Hope it solves your problem too!

0
source

Source: https://habr.com/ru/post/1334043/


All Articles