您能帮忙吗:不建议使用“ downloadURL()”:使用StorageReference.downloadURLWithCompletion()
获取当前的下载URL。
Storage.storage().reference().child("profile_images").child(filename).putData(uploadData, metadata: nil, completion: { (metadata, err) in
if let err = err {
print("Failed to upload profile image:", err)
return
}
guard let profileImageUrl = metadata?.downloadURL()?.absoluteString else { return }
print("Successfully uploaded profile image:", profileImageUrl)
guard let uid = user?.uid else { return }
let dictionaryValues = ["username": username, "profileImageUrl": profileImageUrl]
let values = [uid: dictionaryValues]
Database.database().reference().child("users").updateChildValues(values, withCompletionBlock: { (err, ref) in
if let err = err {
print("Failed to save user info into db:", err)
return
}
print("Successfully saved user info to db")
})
})