【发布时间】:2018-11-09 17:47:10
【问题描述】:
使用 Xcode 10.1、Swift 4.2 和 Firebase ##
使用以下代码将数据上传到 Firebase 后,我无法在实时数据库中看到数据:
static func createUser(username: String, email: String, password: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ error: String?) -> Void) {
Auth.auth().createUser(withEmail: email, password: password) { (data, error) in
if let err = error {
onError(err.localizedDescription)
return
}
// User erfolgreich erstellt
guard let uid = data?.user.uid else { return }
self.uploadUserData(uid: uid, username: username, email: email, imageData: imageData, onSuccess: onSuccess)
}
}
static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void) {
let storageRef = Storage.storage().reference().child("profile_image").child(uid)
storageRef.putData(imageData, metadata: nil) { (metadata, error) in
if error != nil {
return
}
}
storageRef.downloadURL(completion: { (url, error) in
if error != nil {
print(error!.localizedDescription)
return
}
let profilImageURL = url?.absoluteString
let ref = Database.database().reference().child("users").child(uid)
ref.setValue(["username" : username, "email" : email, "profileImageURL": profilImageURL ?? "Kein Bild vorhanden"])
})
onSuccess()
}
firebase 中的设置:
应该以正确的方式工作。我已经查看了 firebase 文档,但没有找到更多信息。
【问题讨论】:
-
你确定user has write permission到
/users/$uid吗? -
对不起我的错误。编辑了图片。读写为真。
-
感谢分享。请始终将文本内容作为文本发布。文字图片几乎不能重复使用和搜索。
-
所以你是说你的数据库在运行这段代码后仍然是空的?
-
是的,在这段代码之后我的实时数据库是空的
标签: swift firebase firebase-realtime-database