我没有什么问题。我使用以下 URL
进行缓存:
let URL = NSURL(string: "https://raw.githubusercontent.com/onevcat/Kingfisher/master/images/kingfisher-\(indexPath.row + 1).jpg")!
但无法使用此 URL
让它像这样工作:
FIRStorage.storage().reference().child("\(productImageref!).png").downloadURLWithCompletion({(url, error)in
if error != nil{
print(error)
return
}else{
cell.snusProductImageView.kf_setImageWithURL(url , placeholderImage: nil,
optionsInfo: [.Transition(ImageTransition.Fade(1))],
progressBlock: { receivedSize, totalSize in
print("\(indexPath.row + 1): \(receivedSize)/\(totalSize)")
},
completionHandler: { image, error, cacheType, imageURL in
print("\(indexPath.row + 1): Finished")
})
}
})
我在这里做错了什么?你能给我指出正确的方向吗?对于缓存,我使用第 3 方库“KingFisher”
编辑:Firebase 人 Mike McDonald 的引述
"The Github one has Cache-Control: max-age=300 while Firebase Storage doesn't have cache control set by default (you can set it when you upload the file, or change it by updating metadata), so I assume that's why KingFisher isn't caching it."
KingFisher 所有者 quotes .
最佳答案
就像 Firebase 人 Mike McDonald 说的那样,我在将图像上传到 Firebase 存储时直接设置了缓存控制。然后在后面加载的时候会正确缓存。
(配置:Swift3,Firebase Storage 3.11.0)
let storage = FIRStorage.storage()
let storageRef = storage.reference(forURL: yourFirebaseStorageReferenceURL)
let imageRef = storageRef.child("profileImages/\(imageUUID).jpg")
let metadata = FIRStorageMetadata()
metadata.contentType = "image/jpeg"
// THIS is the important part
metadata.cacheControl = "public,max-age=2592000"
let uploadTask = imageRef.put(imageData, metadata: metadata) { (metadata, error) in
if let error = error
{
completion(.failure(error as NSError))
}
guard let metadata = metadata, let downloadURL = metadata.downloadURL()?.absoluteString else {
// Handle upload error
return
}
// Handle successful upload
}
当我下载图片时,设置了缓存控制
关于swift - 图片不使用 Firebase url 缓存,但使用其他缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38979706/