I want to let URL image update immediately when I uploaded new image, but it always display previous uploaded image.
func changeUserIMG(imgURL:String){
if let url = URL(string: imgURL) {
URLSession.shared.dataTask(with: url, completionHandler: {(data,responds,error) in
if error != nil{
print(error!.localizedDescription)
}
else if let imageData = data{
DispatchQueue.main.async {
self.userImage.image = UIImage(data: imageData)
}
}
}).resume()
}
}
Is there anyway to overwrite or ignore UIImage chache?
edit:
func changeUserIMG(imgURL:String){
if let url = URL(string: imgURL) {
let request = URLRequest.init(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 60)
URLSession.shared.dataTask(with: request,completionHandler: {(data,responds,error) in
if error != nil{
print(error!.localizedDescription)
}else{
DispatchQueue.main.async {
self.userImage.image = UIImage(data: data!)
}
}
}).resume()
}
Even I try to use .reloadIgnoringLocalCacheData, still display previous uploaded image.
Where's the problem?