ios - 如何检查 Firebase 中是否存在用户名

标签 ios swift firebase firebase-realtime-database firebase-authentication

I have the following structure in my Firebase:

users ->
         uid ->
               provider: "facebook.com"
               username: "vandanpatel"

当我登录用户时,我只想检查他是否已经设置了用户名。我有获取当前用户的机制。我只想检查当前用户是否有“用户名”字段。我已经尝试了一切,但似乎没有什么对我有用。如果他们没有“用户名”字段,我会让他们选择“用户名”并进行设置。

最佳答案

你可以尝试:-

    FIRDatabase.database().reference().child("users/\(FIRAuth.auth()!.currentUser!.uid)/username").observeSingleEvent(of: .value, with: {(snap) in

        if snap.exists(){

            //Your user already has a username

        }else{

            //You need to set the user's name and the the required segue

        }
    })

另请检查此链接:- Check if username already exists

关于ios - 如何检查 Firebase 中是否存在用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39928182/

相关文章:

ios - 无法使用 NSCoding 归档嵌套自定义对象

ios - 如何使用NSPredicate以与完整NSArray相同的顺序对NSSet子集进行排序?

swift - 当 allowedCameraControl = true 时,如何禁用场景 View 中的某些默认功能?

ios - NSURLSessionDownloadTask API 调用 Swift 语法说明

typescript - 在 ngfor angular 6 中获取数据 Firebase 而不是使用 angularFire

javascript - 不在 forEach 语句中推送元素

ios - 为什么我的 ScrollView 页面无法在我的 iOs 应用程序上加载?出现错误 : EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, 子代码=0x0)

ios - 迦太基中 “--cache-builds” 的目的是什么?

swift - 如何修复线程 1 : Fatal error: Unexpectedly found nil for UIScrollView

javascript - 具有对外部 api 的基本身份验证的获取请求的 Firebase 云功能