我的回调未被调用。我不熟悉dispatch_async所以有什么想法吗?重点是,我从未看到过响应。
+ (void)asyncRequest:(NSURLRequest *)request
success:(void(^)(NSData *, NSURLResponse *))successBlock_
failure:(void(^)(NSData *, NSError *))failureBlock_
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
NSString *result = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"-----------------result %@", result);
if (error) {
failureBlock_(data,error);
} else {
successBlock_(data,response);
}
[pool release];
});
}
答案 0 :(得分:1)