Kingfisher載入不出帶逗號的圖片url

weixin_34365417發表於2016-11-03

ps:不是逗號的原因,但是逗號是這個url的特徵,方便搜尋
使用版本:3.1.3
如:http://img2.imgtn.bdimg.com/it/u=2627069709,2509213581&fm=21&gp=0.jpg

解決

參考
https://github.com/rs/SDWebImage/issues/1228

ImageDownloader.swift檔案299行加入User-Agent

    func downloadImage(with url: URL,
              retrieveImageTask: RetrieveImageTask?,
                        options: KingfisherOptionsInfo?,
                  progressBlock: ImageDownloaderProgressBlock?,
              completionHandler: ImageDownloaderCompletionHandler?) -> RetrieveImageDownloadTask?
    {
        if let retrieveImageTask = retrieveImageTask, retrieveImageTask.cancelledBeforeDownloadStarting {
            return nil
        }
        
        let timeout = self.downloadTimeout == 0.0 ? 15.0 : self.downloadTimeout
        
        // We need to set the URL as the load key. So before setup progress, we need to ask the `requestModifier` for a final URL.
        var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: timeout)
        request.httpShouldUsePipelining = requestsUsePipeling
      //這兒
        request.allHTTPHeaderFields = ["User-Agent":"App/iOS"]
....下面省略

相關文章