check when two NSOperationQueue have finished to c

2019-08-23 00:47发布

in my app i have some NSOperation that update some core data element from a online database, sometime the update require some minute, and when the screen of iPhone lock, the app enter in the background mode, and this update is stopped, so i have to reopen the app to continue the update, so i have asked this some minute ago on SO, i have received this correct answer:

- (void)someMethodToKeepRunningInBackground {
UIBackgroundTaskIdentifier taskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(void) {
    // Uh-oh - we took too long. Stop task.
}];

// Perform task here
CheckForUpdate *checkUpdate = [[CheckForUpdate alloc] init];
[sectionCheckUpdateQueue addOperation:checkUpdate];       

if (taskId != UIBackgroundTaskInvalid) {
    [[UIApplication sharedApplication] endBackgroundTask:taskId];
}
}

the problem is that i have the more NSOperationQueue that run to perform the update, the sectionCheckUpdateQueue that i write above, that if found update schedule more NSOperation on other NSOperationQueue, so i can't call this:

endBackgroundTask:taskId

because i don't know when this NSOperationQueue are finished, so my question is, so how i can detect when this NSOperationQueue are finished so to call the endBacgkround:taskId?

1条回答
登录 后发表回答