NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
UIImage *image = [UIImage imageWithData:data];
在使用https的圖片在某些情況下使用這種方法會(huì)造成data返回為null脖隶,可嘗試替換SDWebImage
油挥,但特殊情況下https依舊無法顯示潦蝇,事實(shí)上SDWebImage實(shí)際上是支持HTTPS的款熬,但很多HTTPS站點(diǎn)都是用了自簽名的SSL證書,就像瀏覽器會(huì)報(bào)不安全警告一樣攘乒,SDWebImage也并不信任自簽名的SLL證書贤牛。
此時(shí)情況增添SDWebImage下的options
為 SDWebImageAllowInvalidSSLCertificates
即可跳過無效的SSL證書
另:如果僅出現(xiàn)個(gè)別機(jī)型需要更改SDWebImageAllowInvalidSSLCertificates
才可顯示https圖片而其他機(jī)型無此問題。
此時(shí)讓后臺(tái)查詢下自己的SSL證書設(shè)置的!時(shí)間!
,將時(shí)間不要設(shè)置太靠前即可恢復(fù)
[[SDWebImageManager sharedManager]loadImageWithURL:[NSURL URLWithString:urlStr] options:SDWebImageAllowInvalidSSLCertificates progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
CGFloat imageHeight = 0;
if (image.size.width != 0) {
imageHeight = image.size.height/image.size.width * (kScreenWidth-24);//按所需控件比例計(jì)算圖片高度
}
cellHeight+=(imageHeight+24);
}];
[imgView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:nil options:SDWebImageAllowInvalidSSLCertificates];