【问题标题】:Execution path trouble with Firebase in SwiftSwift 中 Firebase 的执行路径问题
【发布时间】:2016-09-07 19:15:48
【问题描述】:

我有一个设置,在一个文件(LoginDelegate)中,我有一个检查用户是否存在的功能:

class LogInDelegate {
    func userCheck(email: String, completion: (Bool) -> Void) {
        authUserCheck() {
            let usersRef = FIRDatabase.database().reference().child("users")

            usersRef.queryOrderedByChild("email").queryEqualToValue("\(email)").observeEventType(.Value, withBlock: { snapshot in
                if (snapshot.value is NSNull) { completion(false) }
                else { completion(true) }
            })
        }
    }
}

在我的视图控制器上,我有一些其他功能可以检查几个文本字段的更改,如果用户输入了有效的电子邮件和足够长的密码,则执行此功能:

self.forwardButton.enabled = true
delegate.userCheck(email) { userExists in
    if userExists {
        self.forwardButton.setTitle(buttonTitle.login.rawValue, forState: .Normal)
    } else {
        self.forwardButton.setTitle(buttonTitle.new.rawValue, forState: .Normal)
    }
}

第一次调用 userCheck 函数时,不执行 .observeEventType 闭包。您必须对文本字段进行另一次更改,以便第二次调用 userCheck,然后执行闭包。

为什么第一次没有执行?是因为嵌套的闭包吗?如果是这样,我该怎么办?

【问题讨论】:

  • 什么是authUserCheck()?
  • 未经身份验证无法访问数据库中的用户列表,因此 authUserCheck 登录数据库进行检查,并在检查后退出。
  • 您是否要检查电子邮件是否已存在于数据库中?如果它确实提示用户。?
  • 它会自动在登录和注册之间切换。所以,是的,有点。

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


【解决方案1】:

发现我的问题。在 authUserCheck 中,登录并执行闭包后,它立即注销,所以它没有给网络请求做它的时间。

【讨论】:

  • 我怀疑authUserCheck 搞砸了。恭喜你弄明白了! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-29
  • 2011-10-24
  • 2016-12-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多