如何更新用户资料
Posted
技术标签:
【中文标题】如何更新用户资料【英文标题】:How to update a user profile 【发布时间】:2020-04-02 20:17:04 【问题描述】:当我的用户注册时,他们使用个人资料图片和直接保存到 firebase 数据库中的用户名。用户注册后,(个人资料图片和用户名)等用户信息不会出现在更新的用户个人资料屏幕上,我该如何更新用户个人资料
Auth.auth().addStateDidChangeListener auth, user in
if Auth.auth().currentUser != nil
guard let uid = Auth.auth().currentUser?.uid else
return
Database.database().reference().child("users").child(uid).observeSingleEvent(of: .value, with: (snapshot) in
guard let dict = snapshot.value as? [String: Any] else return
let user = Auth.auth().currentUser
if let user = user
let uid = user.displayName
let Profilephoto = self.ProfileImage
self.DisplayName.text = user?.displayName
func getData(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ())
URLSession.shared.dataTask(with: url, completionHandler: completion).resume()
func downloadImage(from url: URL)
getData(from: url)
data, response, error in
guard let data = data, error == nil else
return
DispatchQueue.main.async()
self.ProfileImage.image = UIImage(data: data)
let DisplayName = user?.displayName
let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
changeRequest?.displayName = DisplayName
changeRequest?.commitChanges (error) in
【问题讨论】:
您的个人资料图片是保存在 Firebase 数据库还是 Firebase 存储中? 【参考方案1】:好像self.ProfileImage
有点像UIImageView
。
试试self.ProfileImage.image = UIImage(data: data)
【讨论】:
以上是关于如何更新用户资料的主要内容,如果未能解决你的问题,请参考以下文章
Meteor:我应该如何更新用户集合以在对象/字典中包含一个新属性?