我是新工作的firebase,我正在登录并使用firebase为应用注册窗口。
现在,只要我从控制台创建帐户,登录就可以正常工作 This is what the login code looks like
但是如果你想要创建一个新帐户,你可以点击那个按钮,然后它会带你到一个新的viewcontroller窗口,在那里我添加了一些东西来填充以创建一个新帐户并且我使用了
FIRAuth.auth()?.createUserWithEmail(<email: String>, password: <String>, completion: <FIRAuthResultCallback?(FIRUser?, NSError?) -> Void#>)
这里是代码看起来如何的图片 picture of the code and the imageview
当我尝试注册一个新用户时,我得到了无效的消息,我真的不知道它为什么不创建一个新用户
奖金问题 当我让它工作时如何让它从那个窗口移动到另一个窗口?
答案 0 :(得分:3)
这应该有效:
var ref: FIRDatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
// Do any additional setup after loading the view.
}
@IBAction func signup(sender: AnyObject) {
if let em = email.text, pass = password.text{
FIRAuth.auth()?.createUserWithEmail(email.text!, password: password.text!) {(user, error) in
if let error = error {
print(error.localizedDescription)
}
else {
print("User signed in!")
self.ref.child("data/users").updateChildValues(["\(FIRAuth.auth()!.currentUser!.uid)":["Username":self.username.text!]])
self.performSegueWithIdentifier("home", sender: self)
//At this point, the user will be taken to the next screen
}
} }
else{
print("You left email/password empty")
}
}
确保您已安装Firebase,FirebaseAuth和FirebaseDatabase(如果您正在使用cocoapods,则您的pod应如下所示)
pod 'Firebase'
pod 'Firebase/Auth'
pod 'Firebase/Database'
答案 1 :(得分:0)
迅速5
尝试我的代码小巧易懂
import UIKit
import Firebase
class RegisterViewController: UIViewController {
@IBOutlet weak var emailTextfield: UITextField!
@IBOutlet weak var passwordTextfield: UITextField!
@IBAction func registerPressed(_ sender: UIButton) {
if let email = emailTextfield.text, let password = passwordTextfield.text {
Auth.auth().createUser(withEmail: email, password: password) { authResult, error in
if let e = error {
print(e.localizedDescription)
} else {
//Navigate to the ChatViewController
self.performSegue(withIdentifier: "RegisterToChat", sender: self)
}
}
}
}
}