成功通话后不支持的URL错误

时间:2015-08-25 16:22:16

标签: ios dispatch-async

即使图像下载并成功显示,我也很困惑为什么错误块正在调用。我在日志中得到的错误是,

  

错误=错误域= NSURLErrorDomain代码= -1002"不支持的URL" UserInfo = 0x7fe7840d8000 {NSUnderlyingError = 0x7fe781d5b5e0"不支持的URL",NSErrorFailingURLStringKey =,NSErrorFailingURLKey =,NSLocalizedDescription =不支持的URL}

即使我收到此错误,我也可以获取图片,解析并在应用中显示。我在这个代码中哪里错了,

@try{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSURL *url = [NSURL URLWithString:imageUrl];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *res, NSData *data, NSError *error){
 UIImage *thumbImage = nil;
 if ([data length] >0 && error == nil){
    NSLog(@"image was downloaded.");
    thumbImage = [UIImage imageWithData:data];
 }
 else if ([data length] == 0 && error == nil){
    NSLog(@"Nothing was downloaded.");
    [loaderView removeFromSuperview];
 }
 else if (error != nil){
    NSLog(@"Error = %@", error);
    [loaderView removeFromSuperview];
 }
  dispatch_async(dispatch_get_main_queue(), ^{
    imageViewtoApply.image = thumbImage;
    [webServiceDelegate imageDownloadFinished];
    [loaderView removeFromSuperview];
    });
   }];
 });
}

1 个答案:

答案 0 :(得分:0)

检查http状态代码,它可能是错误代码。

将回复转发给JTable并检查NSHTTPURLResponse属性。

statusCode