SDWebImage 加載圖片不顯示問題


[cell.imageView setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"Icon.png"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {

        NSLog(@"%@",error);

    }];

無法顯示請求圖片,只顯示 placeholderImage圖片;


原因:iOS9以後,http協議改成了https協議,所以不能直接在http協議下GET/POST

解決方法1:直接在工程 info.plist文件下添加代碼
  
 
  

<key>NSAppTransportSecurity</key>

<dict>

<key>NSAllowsArbitraryLoads</key>

        <true/>

    </dict>

如圖:

解決方法2:
在代碼行,使用字符串替換,

NSString * str1 = @「http」

NSString * str2=[str1 stringByReplacingOccurrencesOfString:@"http" withString:@"https"];