我自学了一年多以前如何在线编码。我在自己的应用程序上取得了很小的进步。在尝试创建新用户时,我不断收到相同的错误代码。 " updateChildValues:at / failed:permission_denied"下面我将发布我的代码副本,请帮帮我。
@IBAction func btnLogin(_ sender: Any) {
}
@IBOutlet weak var btnLogin: UIButton!
@IBOutlet weak var txtPassword: UITextField!
@IBOutlet weak var txtUserName: UITextField!
@IBAction func Signup(_ sender: UIButton) {
}
if txtUserName.text != "" && txtPassword.text != ""
{
}
Auth.auth().signIn(withEmail: txtUserName.text!, password: txtPassword.text!) { (user, error) in
if user != nil
{
//Sign in successful
self.performSegue(withIdentifier: "segue", sender: self)
}
else
{
}
if let myError = error?.localizedDescription
{
print(myError)
}
else{
print("Error")
}
}
let ref = Database.database().reference(fromURL: "https://odd-jobs-llc.firebaseio.com/")
observeKeyboardNotifications()
ref.updateChildValues(["Customers": 123123])
}
请帮我克服这堵砖墙。我真的很感激。谢谢你有一个美好的夜晚 扎克
答案 0 :(得分:1)
试试这个
@IBOutlet weak var btnLogin: UIButton!
@IBOutlet weak var txtPassword: UITextField!
@IBOutlet weak var txtUserName: UITextField!
// Assuming this is the button you want to tap to signup the user
@IBAction func Signup(_ sender: UIButton) {
if txtUserName.text != "" && txtPassword.text != "" {
Auth.auth().createUser(withEmail: txtUserName.text!, password: txtPassword.text!) { (user, error) in
if user != nil {
print("Registration success! Now I can do whatever I want in this block")
} else {
// telling you what went wrong
print(error?.localizedDescription)
}
}
} else {
print("One of your field is empty")
}
@IBAction func btnLogin(_ sender: Any) {
if txtUserName.text != "" && txtPassword.text != "" {
Auth.auth().signIn(withEmail: txtUserName.text!, password: txtPassword.text!) { (user, error) in
if user != nil {
//Sign in successful
let ref = Database.database().reference(fromURL: "https://odd-jobs-llc.firebaseio.com/")
observeKeyboardNotifications()
ref.updateChildValues(["Customers": 123123])
self.performSegue(withIdentifier: "segue", sender: self)
} else {
if let myError = error?.localizedDescription {
print(myError)
} else{
print("Error")
}
}
}
}
}
答案 1 :(得分:0)
默认情况下,数据库只能由经过身份验证的用户读取/写入。您必须允许对数据库进行未经身份验证的访问。