2016-08-30 55 views
0

我目前正在使用Firebase来管理我的用户。我喜欢,我可以在我的用户的相关信息,如电子邮件,photoUrl等存储到Firebase检索user.email与用户ID

let user = FIRAuth.auth()?.currentUser 

user?.updateEmail("[email protected]") { error in 
    if let error = error { 
    // An error happened. 
    } else { 
    // Email upenter code heredated. 
    } 
} 

现在当然这仅适用于用户当前的标志性工作的想法,如果我想获取其他用户的相同信息通过使用另一个用户ID我如何检索这个。

+1

没有内置的API来看看通过他们的UID提供用户的信息。出于这个原因,大多数开发人员将用户信息列表保存在另一个数据源(例如Firebase数据库)中。请参阅http://stackoverflow.com/questions/28735377/where-does-firebase-save-its-simple-login-users –

+0

谢谢弗兰克。 – pprevalon

回答

1

您可以在您的数据库的JSON树中创建一个“用户”子项,并将每个用户的用户ID分开,您可以使用FIRAuth.auth()?.currentUser.uid获得该用户ID。

所以,你的JSON树会是这个样子:

"root" 
    "users" 
     "userID12345" 
      "email" 
      "photoURL" 

然后你可以拉在你的应用程序从火力地堡的数据通过调用:

FIRDatabase.database().reference().child("users").observeEventType(.Value, withBlock: { (snapshot) in 
//store the snapshot.value in a dictionary and read your data from there 
})