【问题标题】:AFNetworking setImageWithURLRequest not workingAFNetworking setImageWithURLRequest 不起作用
【发布时间】:2018-12-12 12:52:07
【问题描述】:

我无法下载图像,setImageWithURLRequest 方法不在成功/失败块内。请有人告诉我如何解决这个任务。这是我的代码。

__weak UIImageView *images ;


 NSString *url =[NSString stringWithFormat:@"%@%@",imageBaseUrl,eachImage];
            NSLog(@"image download url %@",url);
            [images setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]
                                         placeholderImage:nil
                                                  success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
                                                      if(response){
                                                          [arr addObject:image];
                                                          NSLog(@"Success fetching image");
                                                      }else{
                                                          NSLog(@"The image data is not there");
                                                      }
                                                  } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
                                                      NSLog(@"Request failed with error: %@", error);
                                                  }];

【问题讨论】:

标签: ios objective-c afnetworking


【解决方案1】:

我已经检查了上面的代码,它适用于其他图像 URL。当我使用您的图片 URL 时,无法加载图片。

如果您手动将 http:// 添加到 URL。然后图像被正确加载。

你的网址应该是http://3.0.191.16/uploads/patient/2133/38049.jpg

您的逻辑应该如下所示。

如果 url 不包含 http 然后手动附加 http:// 否则使用来自服务器的 url。

或者您可以要求 API 开发人员发送正确的图像 URL。

如果对您有用,请标记为接受。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多