有没有办法像 FIRDatabase“.childChanged”那样监听 FIRStorage 子项的更改?我的存储中有个人资料图像,每当用户更改它们时,我想触发我的应用程序使用我的 SAMCache 方法重新缓存它们。
最佳答案
没有办法监听 FIRStorage 的更改。相反,您可以生成 downloadUrl 或随机值,然后将其存储在数据库中。然后您可以监听数据库中该子项的更改。
根据文档修改的示例:
// Upload the file to the path "images/rivers.jpg"
let uploadTask = riversRef.putData(data, metadata: nil) { (metadata, error) in
guard let metadata = metadata else {
// Uh-oh, an error occurred!
return
}
// Metadata contains file metadata such as size, content-type, and download URL.
let downloadURL = metadata.downloadURL
ref.child("/users/\(userId)/profileImage").setValue(downloadURL)
}
然后还将监听器附加到 ref.child("/users/(userId)/profileImage")。
关于swift - FIRStorageReference 观察 Swift 的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44980005/