Does the code still run in the background even after backgroundTimeRemaining is zero?

UIApplication *application = [UIApplication sharedApplication]; UIBackgroundTaskIdentifier background_task = 0; background_task = [application beginBackgroundTaskWithExpirationHandler: ^{ [application endBackgroundTask:background_task]; }]; SEL selector = NSSelectorFromString(action); timer = [NSTimer scheduledTimerWithTimeInterval:floatUpdateInterval target:self selector:selector userInfo:nil repeats:YES]; 

The above code (timer) still works even after backgroundTimeRemaining is 0 (zero). How could this happen? Is there a 10 minute maximum for the above approach?

Is the above code "application repository" safe to send?

+6
source share
1 answer

A timer is being created that is just scheduled to be repeated. beginBackgroundTaskWithExpirationHandler will be called when time is up, this is your chance to stop everything that did not end on time.

You must invalidate your timer in beginBackgroundTaskWithExpirationHandler.

0
source

All Articles