我的代码太老了,不适合用元数据进行pod更新。
let newImageRef = imageStorageRef.child(newPostRef.key!)
let newImageRef1 = imageStorageRef.child(newPostRef1.key!)
newImageRef.putData(imageData).observe(.success, handler: {(snapshot) in
self.imageDownloadURL = snapshot.metadata?.downloadURL()?.absoluteString
newPostRef.setValue(self.imageDownloadURL as Any)
})
newImageRef1.putData(imageData).observe(.success, handler: {(snapshot) in
self.imageDownloadURL = snapshot.metadata?.downloadURL()?.absoluteString
let keyToPost = Database.database().reference().child("people").child(uid).childByAutoId().key
let f1: [String: Any] = [(keyToPost) : self.imageDownloadURL as Any]
newPostRef1.updateChildValues(f1)
})
有人建议做如下修正,但会产生一个错误: 只能存储NSNumber, NSString, NSDictionary类型的对象。现在我打算把集合值和更新子值改为NSString。
newImageRef.putData(imageData).observe(.success, handler: {(snapshot) in
newImageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
return
}
newPostRef.setValue(url)
}
})
newImageRef1.putData(imageData).observe(.success, handler: {(snapshot) in
newImageRef1.downloadURL { (url, error) in
guard let downloadURL = url else {
return
}
let keyToPost = Database.database().reference().child("people").child(uid).childByAutoId().key ?? "I am a default value"
let f1: [String: Any] = [(keyToPost) : newImageRef1.downloadURL as Any]
newPostRef1.updateChildValues(f1)
}
})