gpt4 book ai didi

ios - Firebase 数据库

转载 作者:行者123 更新时间:2023-11-30 12:39:20 26 4
gpt4 key购买 nike

问题:由于某种原因,数据没有发送到我在 firebase 中的数据库。谁能弄清楚为什么信息没有被发送吗?

我用//******** 突出显示了代码,以显示我将其发送到的位置。

规则:

{
"rules": {
".read": "true",
".write": "true"

}
}

import UIKit
import Firebase
import FirebaseDatabase
import KeychainSwift




class SignUpController: UIViewController {

//INPUT - from keyboard email & password
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!

//Data Base Initialization
//var ref: FIRDatabaseReference!

let dataRef = FIRDatabase.database().reference()

override func viewDidLoad() {
super.viewDidLoad()


}

//PROCESS - Checks is user has already been logged in
override func viewDidAppear(_ animated: Bool) {

let currentUser = FIRAuth.auth()?.currentUser

if currentUser != nil {
performSegue(withIdentifier: "SignIn", sender: nil)
}


}

func CompleteSignIn(id: String){
let keyChain = DataService().keyChain
keyChain.set(id , forKey: "uid")
}


//If SignUp button is pressed user will be directed to sign up page
@IBAction func LoginPressed(_ sender: Any) {
self.performSegue(withIdentifier: "BackToLogin", sender: nil)
}





/*If both password and email contain text lets put them into string variables
called email & password. Creates user and authorizes sign in */

@IBAction func SignIn(_ sender: Any){

if let email = emailField.text, let password = passwordField.text {

FIRAuth.auth()?.signIn(withEmail: email, password: password) { (user, error) in
if error == nil {

self.CompleteSignIn(id: user!.uid) //Completese Database Sign in
//************************************************
//Send information to Database
let userEmail : String = self.emailField.text!
let userPassword : String = self.passwordField.text!
let userID : String = user!.uid
self.dataRef.child("Users").child(userID).setValue(["Email": userEmail, "Password" : userPassword])
//************************************************
print("Sign in Test")

self.performSegue(withIdentifier: "SignIn", sender: nil)

} else {
FIRAuth.auth()?.createUser(withEmail: email, password: password) { (user, error) in
if error != nil {

Alerts().invalidSignUpAlert(sender: self) //Alert for invalid email & Password
print("cant sign in user") //Programmer Debugging

} else {
self.CompleteSignIn(id: user!.uid)
self.performSegue(withIdentifier: "SignIn", sender: nil)
}
}
}
}
}
}
}

最佳答案

在规则中添加“用户”,如下所示:

"rules": {
"Users":{
".read": "true",
".write": "true"
}
}

关于ios - Firebase 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42434659/

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