如何与块结合ASIHTTPRequest到GCD并发队列我怎样才能纳入ASIHTTPRequest以块为GCD并发队列
目前我使用这种方式做。我不想比较GCD队列和ASINetworkQueue。这里我使用GCD队列和想知道的是我在做正确的
NSString *urlString = [NSString stringWithFormat:@"http://mysite.com/news_detail/",tagID];
NSURL *url = [NSURL URLWithString:urlString];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request setCachePolicy:ASIAskServerIfModifiedWhenStaleCachePolicy | ASIFallbackToCacheIfLoadFailsCachePolicy];
[request setDelegate:self];
[request setCompletionBlock:^{
dispatch_queue_t JSONProcessingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(JSONProcessingQueue, ^{
dispatch_sync(JSONProcessingQueue, ^{
NSData *responseData = [request responseData];
[self processData:responseData];
});
dispatch_sync(dispatch_get_main_queue(), ^{
[self DisplayNews];
});
});
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"Error in downloading : %@", error.localizedDescription);
}];
[request startAsynchronous];
不要这样。你正在执行线程的线程化。你的实际需求是什么? – nadavhart