1.含中文等特殊符号,需要转义一下。
NSString *url = [model.pic stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[self.brandImage sd_setImageWithURL:[NSURL URLWithString:url ] placeholderImage:[UIImage imageNamed:@"商品图_默认图"] options:SDWebImageRetryFailed];
2.可能是由于图片链接有问题,将获取到的图片链接放到浏览器中试一下.打不开就找后台兄弟。
3.检查Info.plist里NSAllowsArbitraryLoads是否支持http链接。
解决方法:在Info.plist中添加NSAppTransportSecurity类型Dictionary。
在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES
iOS 9 中默认使用的请求协议是 HTTPS。HTTP 发送不成功。
4.因为该图片的格式是WebP,所以需要导入SDWebImage的WebP插件。
pod 'SDWebImageWebPCoder'
fodfile里导入上面的库,或手动添加到项目里,AppDelegate文件添加一下代码
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
SDImageWebPCoder * webPCoder = [SDImageWebPCoder sharedCoder]; [SDImageCodersManager sharedManager] addCoder:webPCoder];
5.虽然是https都链接,但是可能是SSL证书的问题。我的就是这个解决了。
还有一种可能就是图片过大,加载其实要很长时间的
设置options为SDWebImageAllowInvalidSSLCertificates。虽然是Https的链接,最后却是未验证的SSLCertificates
[self.brandImage sd_setImageWithURL:[NSURL URLWithString:url ] placeholderImage:[UIImage imageNamed:@"商品图_默认图"] options:SDWebImageAllowInvalidSSLCertificates];