【发布时间】:2015-11-11 01:05:49
【问题描述】:
我试图在 currentQueue 上运行AFURLConnectionOperation,因为我想让我的主线程保持空闲以供用户交互,但是当我调用 mainQeue 时没有任何反应。
但是,如果我在 mainQueue 上调用相同的 AFURLConnectionOperation,它会完美运行。
请看以下代码
// Send Batch
NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:mutableOperations progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
NSLog(@"%lu of %lu complete", (unsigned long)numberOfFinishedOperations, (unsigned long)totalNumberOfOperations);
} completionBlock:^(NSArray *operations) {
// check batch response
NSError *error;
for (AFHTTPRequestOperation *op in operations) {
if (op.isCancelled){
return ;
}
if (op.responseObject){
// Current JSON Batch complete
NSMutableArray *jsonObject = [NSJSONSerialization JSONObjectWithData:op.request.HTTPBody options:kNilOptions error:&error];
// Update sent_flag using current chunk
[[SyncModel sharedInstance] updateSentFlag:jsonObject];
}
if (op.error){
error = op.error;
NSLog(@"Error == %@", error);
}
}
}];
最后我调用以下代码中的一个或另一个
[[NSOperationQueue mainQueue] addOperations:operations waitUntilFinished:NO]; // this works
[[NSOperationQueue currentQueue] addOperations:operations waitUntilFinished:NO]; // this dose not work
【问题讨论】:
标签: ios objective-c afnetworking nsoperationqueue