2018-05-24SDWebImage 加载图片不显示问题 --- 难以想象的BUG

今天碰到一个BUG

  1. [self.headImage sd_setImageWithURL:[NSURL URLWithString:_model.EAImg] placeholderImage:[UIImage imageNamed:@"gd"]];

多么正常的异步加载图片,他就不正常的显示了,只显示placeholderImage,其他页面倒是可以正常显示,区别就是图片的URL;这个URL是http的,别的是HTTPS;查了一些资料,说是URL问题;解决方法也有;

  1. [self.headImage sd_setImageWithURL:[NSURL URLWithString:_model.EAImg] placeholderImage:[UIImage imageNamed:@"gd"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  2. //在这里输出下error
  3. }];

error:

一、Error Domain=NSURLErrorDomain Code=403 “The operation couldn’t be completed. (NSURLErrorDomain error 403.)”

  1. //SDWebImage 一个难以想象的BUG

  2. NSString *userAgent = @"";

  3. userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];

  4. if (userAgent) {

  5. if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) {

  6. NSMutableString *mutableUserAgent = [userAgent mutableCopy];

  7. if (CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, (__bridge CFStringRef)@"Any-Latin; Latin-ASCII; [:^ASCII:] Remove", false)) {

  8. userAgent = mutableUserAgent;

  9. }

  10. }

  11. [[SDWebImageDownloader sharedDownloader] setValue:userAgent forHTTPHeaderField:@"User-Agent"];

  12. }

  13. [self.headImage sd_setImageWithURL:[NSURL URLWithString:_model.EAImg] placeholderImage:[UIImage imageNamed:@"gd"]];

二、Error Domain=NSURLErrorDomain Code=406 “The operation couldn’t be completed. (NSURLErrorDomain error 406.)”

//请求之前加上这句话

  1. [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8"
  2. forHTTPHeaderField:@"Accept"];
    原文
    https://blog.csdn.net/wujakf/article/details/72466447
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容