Search code examples
iosmultitaskingrecording

How to use multitasking for iOS application?


Really confused about multitasking API in iOS, such as beginBackgroundTaskWithExpirationHandler etc.

For instance of recording video, when press button to start recording, we put

 if ([[UIDevice currentDevice] isMultitaskingSupported]) {
        [self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]];
    }

when recording ends

if ([[UIDevice currentDevice] isMultitaskingSupported]) {
        [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
    }

so who can explain what is meaning of these. As you can see, when start recording, the block beginBackgroundTaskWithExpirationHandler is blank( just nothing to do ? ), and what is usage of those codes ?

Pretty much thanks for explaining.


Solution

  • Think of the expiration handler as any error handler. The system only allows the background application to use a limited amount of CPU time, so if you reach this limit, the background operation will be terminated, and your handler is called. Use it to clean up the internal state of your application.