我刚刚在我的应用程序中实现了电子邮件登录(firebase),用户可以在文本字段中手动添加名称,当到达配置文件页面时,找到刚刚在第一个viewController中输入的名称(标签)(这是代码的一部分) of profileViewController)
override func viewDidLoad() {
super.viewDidLoad()
self.user = Auth.auth().currentUser
self.databaseRef.child("user_profiles").child(self.user!.uid).observeSingleEvent(of: .value) { (snapshot:DataSnapshot) in
let snapshotValue = snapshot.value as? NSDictionary
self.name.text = snapshotValue?["name"] as? String
self.handle.text = snapshotValue?["handle"] as? String
if(snapshotValue?["about"] != nil){
self.usernameField.text = snapshotValue?["about"] as? String
}
if(snapshotValue?["profile_pic"] != nil){
let databaseProfilePic = snapshotValue!["profile_pic"] as! String
let data = try? Data(contentsOf: URL(string: databaseProfilePic)!)
self.setProfilePicture(imageView: self.ProfilePicture,imageToSet:UIImage(data:data!)!)
}
self.imageLoader.stopAnimating()
}
}
与Facebook登录不同的是,用户不输入任何数据,但我接受了这一点
let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"first_name,email, picture.type(large)"])
来自FBSDK,那么当用户登录Facebook并进入 Profiles 页面时,如何使用这些参数来查找他的名字(即fb Profiles 名称)?我正试图找到一个解决方案,但我还没有找到任何东西 .
1 回答
创建用户帐户并通过以下方法登录后:
您应该能够使用以下方法访问用户基本配置文件信息:
例如,要获取用户名,您可以:
当您首次通过signIn方法创建用户帐户时,您还可以在数据库中写入所有用户数据,如下所示:
然后使用
usersRef
上的observeSingleEvent(of: .value)
来读取您的用户配置文件数据 .