我以这种方式进行了“批量操作”,并且效果很好
NSMutableArray *mutableOperations = [NSMutableArray array];
for (NSString *stringURL in url_list) {
NSURL *url = [NSURL URLWithString:stringURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFHTTPResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
[self addDataToTotal:[self parseJSONfile:responseObject]];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[mutableOperations addObject:operation];
}
NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:mutableOperations progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
NSLog(@"progress:%f", (float)numberOfFinishedOperations / totalNumberOfOperations);
} completionBlock:^(NSArray *operations) {
NSLog(@"All operations in batch complete");
[self startPopulateDBStructure:self.total];
}];
[[NSOperationQueue mainQueue] addOperations:operations waitUntilFinished:NO];
现在我想使用“可达性属性”来检查连接状态,我这样做了
[[[NSOperationQueue mainQueue]reachabilityManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi:
[[NSOperationQueue mainQueue] setSuspended:NO];
break;
case AFNetworkReachabilityStatusNotReachable:
default:
[[NSOperationQueue mainQueue] setSuspended:YES];
break;
}
}];
但是我收到此消息导致崩溃,问题出在哪里?
[NSOperationQueue reachabilityManager]: unrecognized selector sent to instance