gpt4 book ai didi

ios - 在 firebase 上注册一个新用户

转载 作者:搜寻专家 更新时间:2023-10-31 22:31:53 25 4
gpt4 key购买 nike

我是使用 firebase 的新手,我正在为使用 firebase 的应用程序登录和注册窗口。

现在,只要我从控制台创建帐户,登录对我来说就可以正常工作 This is what the login code looks like

但是如果你想创建一个新帐户,你可以点击下面的那个按钮,它会带你到一个新的 View Controller 窗口,在那里我添加了一些东西来创建一个新帐户,我使用了

FIRAuth.auth()?.createUserWithEmail(<email: String>, password: <String>, completion: <FIRAuthResultCallback?(FIRUser?, NSError?) -> Void#>)

这里是代码的图片 picture of the code and the imageview

当我尝试注册一个新用户时,我收到了不起作用的消息,我真的不知道为什么它不创建一个新用户

奖金问题当我让它工作时,如何让它从那个窗口转到另一个窗口?

最佳答案

这应该有效:

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'

关于ios - 在 firebase 上注册一个新用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37978507/

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