【发布时间】:2018-09-08 03:41:18
【问题描述】:
当用户在应用程序中注册时,下面的代码用于更新我的 firebase 数据库,假设在数据库中对用户进行身份验证并保存一个布尔值。执行此操作时出现以下错误(见下文)。
@IBAction func signupPressed(_ sender: UIButton) {
Auth.auth().createUser(withEmail: emailEntryField.text!, password: passwordEntryField.text!) { (user, error) in
if error == nil {
//Show SVProgressHUD
SVProgressHUD.show()
//save User to Database
let newUserInfo : [String:Any] = ["email":self.emailEntryField.text!, "state":true]
self.ref.child("users").child(user?.user.uid).setValue(newUserInfo, withCompletionBlock: { (error, ref) in
print("New User Saved")
}
//Dismiss SVProgressHUD
SVProgressHUD.dismiss()
//move to info view controller
self.performSegue(withIdentifier: "signupToInfo", sender: self)
} else {
print("Signup Unsuccessul")
let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}
}
【问题讨论】:
标签: swift firebase firebase-realtime-database firebase-authentication