AlamofireImage how to clean memory and cache

前端 未结 1 1256
陌清茗
陌清茗 2021-01-25 03:58

I use Alamofire and AlamofireImage in my app for get data and photos.

        Alamofire.request(.GET, URLString, encoding: .JSON)
        .authenticate(user: use         


        
相关标签:
1条回答
  • 2021-01-25 04:48

    Updated for swift:

    Used below simple function;

    func clearImageFromCache(mYourImageURL: String) {
        let URL = NSURL(string: mYourImageURL)!
        let mURLRequest = NSURLRequest(url: URL as URL)
        let urlRequest = URLRequest(url: URL as URL, cachePolicy: URLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData)
    
        let imageDownloader = UIImageView.af_sharedImageDownloader
        _ = imageDownloader.imageCache?.removeImage(for: mURLRequest as URLRequest, withIdentifier: nil)
        self.mImageView.af_setImage(withURLRequest: urlRequest, placeholderImage: UIImage(named: "placeholder"), completion: { (response) in
            self.mImageView.image = response.result.value
        })
    }
    

    // NOTE:- where placeholder = your_placeholder_image_name

    0 讨论(0)
提交回复
热议问题