Swift& Firebase - 如何存储除电子邮件和密码以外的更多用户数据? [英] Swift & Firebase - How to store more user data other than email and password?

查看:89
本文介绍了Swift& Firebase - 如何存储除电子邮件和密码以外的更多用户数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Firebase相对来说比较陌生,试图开发一个应用程序,要求用户在注册页面上输入姓名和姓氏。但firebase createUserWithEmail方法只存储电子邮件和密码。我怎样才能将这个名字和姓氏数据添加到我的应用程序,并将它们与用户链接?我想我需要使用FIRStorage,但以这种方式,只有选择保存信息是从NSData或NSURL保存,如何保存我的名字和姓氏字符串?



提前感谢!

编辑1:我想我错了,我需要使用实时数据库而不是存储来保存用户数据。但是我仍然需要帮助。我来自Parse,这看起来很复杂。

解决方案

是的,您需要使用实时数据库来存储您的用户数据。所以创建它之后,你可以调用 setValue()

  FIRAuth .auth()!. createUserWithEmail(email,password:pwd,completion:{authData,
中的错误如果错误== nil {
let userData = [name:name,
(姓名):姓氏
let ref = FIRDatabase.database()。reference()
ref.child('users')。child(authData!.uid).setValue(userData)
} else {
//处理错误
}
})


I'm relatively new to Firebase and trying to develop an app which requires users to give their name and surname in sign up page. But firebase createUserWithEmail method only stores email and password. How can I add this name and surname data to my app and link them with the users? I suppose i need to use FIRStorage but in that way, only options to saving information is saving either from NSData or NSURL, how can I save my name and surname strings?

Thanks in advance!

Edit1: I suppose i was wrong, I need to use real time database rather than storage to save user data. But still I need help. I am coming from Parse and this seems complicated.

解决方案

Yes, you need to use the realtime database to store your user data. So after creating it you can call the setValue().

FIRAuth.auth()!.createUserWithEmail(email, password: pwd, completion: { authData, error  in
    if error == nil {    
        let userData = ["name": name,
                        "surname ": surname]
        let ref = FIRDatabase.database().reference()
        ref.child('users').child(authData!.uid).setValue(userData)
    } else {
        // handle error
    }
})

这篇关于Swift& Firebase - 如何存储除电子邮件和密码以外的更多用户数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆