本文介绍了我将如何使用Firebase创建用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我还是新手,用Xcode和Firebase编码。我已经能够创建一个注册和登录页面与Firebase身份验证。我一直在想如何让人们创建自定义的唯一用户名。我一直在网上寻找一段时间,我找不到。我想学习如何在我的应用程序中实现用户名,以便用户可以创建唯一的用户名和自己的配置文件。
解决方案
let currentUserId = FIRAuth.auth()?。currentUser?.uid
let currentUserRef = FIRDatabase.database()。reference(withPath:MainDataBase / users) .child(currentUserId!)// MainDataBase / users - 是你数据库的一部分
currentUserRef.observeSingleEvent(of:.value,with:{snapshot in
self.userInfo = UserItem(snapshot :快照)
self.label.text =Welcome+(self.userInfo.login)!//例如它将显示登录
})
祝您好运
编辑:有这样的东西:
var userInfo:UserItem! {
didSet {
self.label.text =Welcome+(self.userInfo.login)! //例如它将显示登录
//其他操作
}
I am still new to swift and coding with Xcode and using Firebase. I have been able to create a sign up and login page with Firebase authentication. I have been wondering how would I allow people to create custom unique usernames. I have been searching for a while now on the web and I can't find much.
I want to learn how to implement usernames with in my app so users can create unique usernames and have their own profiles.
解决方案In addition to my comment.
let currentUserId = FIRAuth.auth()?.currentUser?.uid let currentUserRef = FIRDatabase.database().reference(withPath: "MainDataBase/users").child(currentUserId!) // MainDataBase/users - is part from you database currentUserRef.observeSingleEvent(of: .value, with: { snapshot in self.userInfo = UserItem(snapshot: snapshot) self.label.text = "Welcome " + (self.userInfo.login)! // for example it will show login })
Good luck
EDIT:Its better to have something like this:
var userInfo: UserItem! { didSet { self.label.text = "Welcome " + (self.userInfo.login)! // for example it will show login // other actions }
这篇关于我将如何使用Firebase创建用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!