我知道如何在 iOS 应用程序进入后台后扩展任务以在后台运行
beginBackgroundTaskWithExpirationHandler
dispatch_async
等等
但是,如果我有一个 NSOperationQueue 想要扩展为后台任务,又不会丢失 NSOperations 的相互依赖关系呢?说我有这个:
NSBlockOperation *op1 = [NSBlockOperation blockOperationWithBlock:^{
// Do stuff
}];
NSBlockOperation *op2a = [NSBlockOperation blockOperationWithBlock:^{
// Do stuff
}];
[op2a addDependency:op1];
NSBlockOperation *op2b = [NSBlockOperation blockOperationWithBlock:^{
// Do stuff
}];
[op2b addDependency:op1];
NSBlockOperation *op3 = [NSBlockOperation blockOperationWithBlock:^{
// Do stuff
}];
[op3 addDependency:op2a];
[op3 addDependency:op2b];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperations: @[op1, op2a, op2b, op3] ];
有没有一种优雅的方式让 NSOperationQueue 在后台完成?