gpt4 book ai didi

swift - 将 Firebase 身份验证与 Firebase 数据库连接

转载 作者:行者123 更新时间:2023-11-30 10:51:07 27 4
gpt4 key购买 nike

我正在努力将 Firebase 身份验证与我的 iOS 应用上的 Firebase 数据库连接起来。

用户已成功通过身份验证并显示在 Firebase 的“身份验证”部分中,但数据(例如姓名/电子邮件)未显示在应存储的 Firebase 数据库中。我已将代码和调试区域的警告粘贴在下面。

代码:

 @objc func handleRegister() {

guard let email = emailTextField.text, let password = passwordTextField.text, let name = nameTextField.text
else {
print("form is not valid")
return
}

Auth.auth().createUser(withEmail: email, password: password, completion: { (res, err) in

if let err = err {
print(err)
return
}


self.ref = Database.database().reference()
let userId = Auth.auth().currentUser?.uid
self.ref.child("users").child(userId!).setValue(["username": name, "email": email]) {
(error:Error?, ref:DatabaseReference) in
if let error = error {
print("Data could not be saved: \(error).")
} else {
print("Data saved successfully!")
}
}

})
}

Warnings of debug area:

2019-02-06 19:29:06.735883+0100 MyAwesomeProject[72154:5241459] libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.

2019-02-06 19:29:06.874146+0100 MyAwesomeProject[72154:5241580] 5.16.0 - [Firebase/Core][I-COR000022] Firebase Analytics is not available. To add it, include Firebase/Core in the Podfile or add FirebaseAnalytics.framework to the Link Build Phase

2019-02-06 19:29:08.015632+0100 MyAwesomeProject[72154:5241459] [framework] CUIThemeStore: No theme registered with id=0

2019-02-06 19:29:09.123610+0100 MyAwesomeProject[72154:5241459] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/mikolajsemeniuk/Library/Developer/CoreSimulator/Devices/20AB5C8F-2A8E-4F49-8DA6-0BB11A11958F/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

2019-02-06 19:29:09.125330+0100 MyAwesomeProject[72154:5241459] [MC] Reading from private effective user settings.

2019-02-06 19:29:19.325723+0100 MyAwesomeProject[72154:5241579] [AutoFill] Cannot show Automatic Strong Passwords for app bundleID: -234567.MyAwesomeProject due to error: iCloud Keychain is disabled 2019-02-06 19:29:23.627072+0100 MyAwesomeProject[72154:5242009] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x7fa94a80b030] get output frames failed, state 8196

2019-02-06 19:29:23.627344+0100 MyAwesomeProject[72154:5242009] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x7fa94a80b030] get output frames failed, state 8196

2019-02-06 19:29:23.628087+0100 MyAwesomeProject[72154:5242009] TIC Read Status [1:0x0]: 1:57

2019-02-06 19:29:23.628233+0100 MyAwesomeProject[72154:5242009] TIC Read Status [1:0x0]: 1:57

2019-02-06 19:29:23.950084+0100 MyAwesomeProject[72154:5241765] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x7fa948614e70] get output frames failed, state 8196

2019-02-06 19:29:23.950399+0100 MyAwesomeProject[72154:5241765] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x7fa948614e70] get output frames failed, state 8196

2019-02-06 19:29:23.951137+0100 MyAwesomeProject[72154:5241765] TIC Read Status [2:0x0]: 1:57

2019-02-06 19:29:23.951409+0100 MyAwesomeProject[72154:5241765] TIC Read Status [2:0x0]: 1:57 (lldb)

最佳答案

首先,您的属性列表文件 plist 决定使用哪个 Firebase 项目,因此无需指定:

let ref = Database.database().reference(fromURL:"https://myawesomeproject29133.firebaseio.com/")

相反,您可以在 viewDidLoad() 函数上方创建一个名为 ref 的全局变量:

var ref: DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()

}

在你的handleUser()中:

ref = Database.database().reference()
let userid = Auth.auth().currentUser.uid
self.ref.child("users").child(userid).setValue(["name": name,"email": email])

Also, I highly recommend you to continue without saving someones password, Unless you encrypt them. You shouldn't store them nakedly. It's stored in Google's servers and you have absolutely zero reasons to view someone else's password.

关于swift - 将 Firebase 身份验证与 Firebase 数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54515410/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com