SDWebImage 加载图片失败但浏览器能打开

1:首先打印错误信息

   [self.bookImgV sd_setImageWithURL:[NSURL URLWithString:@"http://api.newbeebook.com/cover/7/7850.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

    NSLog(@"错误信息:%@",error);

}];

这里的错误原因有很多,可以根据错误原因进行更改。

举个例子:我的error打印如下: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.
2015-11-20 16:12:16.662 AFNetworking_(3.0)[3091:1742917] failure Error Domain=NSURLErrorDomain Code=-1022 “The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.” UserInfo={NSUnderlyingError=0x7fedb8e02ef0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 “(null)”}, NSErrorFailingURLStringKey=http://api.newbeebook.com/cover/7/7850.jpg, NSErrorFailingURLKey=http://api.newbeebook.com/cover/7/7850.jpg, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

原因: 该图片加了访问权限,需要在解锁状态下才能访问图片.

常见原因:iOS9让所有的HTTP默认使用了HTTPS,原来的HTTP协议传输都改成TLS1.2协议进行传输。直接造成的情况就是App发请求的时候弹出网络无法连接。解决方法,在工程里面的Info.plist里面添加如下节点:
还有种新式该法
App Transport Security Settings Dictionary
Allow Arbitrary Loads Boolean Yes

20151120162843123.png

以上只是例子及例子解决方案,具体解决方法要看error的具体原因。

文章参考网址: https://blog.csdn.net/qq_29284809/article/details/49948535
https://blog.csdn.net/qq_18505715/article/details/79701191

你可能感兴趣的:(SDWebImage 加载图片失败但浏览器能打开)