【问题标题】:Firebase create user swift doesn't workFirebase 创建用户 swift 不起作用
【发布时间】:2016-04-28 06:10:35
【问题描述】:

我刚刚输入的下面是错误,显示“无法将类型 '(,) -> Void' 的值覆盖到预期的参数类型 '(NSERROR!) -> Void!)'

在这行代码上:会有什么问题?

FIREBASE_REF.createUser(email, password: password, withCompletionBlock: {(error,authData) -> Void in

@IBAction func creatAccountAction(sender: AnyObject) {
        let email = self.emailTextField.text
        let password = self.passwordTextField.text

        if email != "" && password != ""
        {
            FIREBASE_REF.createUser(email, password: password, withCompletionBlock: {(error,authData) -> Void in

            if error != nil {

                FIREBASE_REF.authUser(email, password: password, withCompletionBlock: { (error, authData) -> Void in

                    if error == nil {

                        NSUserDefaults.standardUserDefaults().setValue(authData.uid, forKey: "uid")
                    }
                    else {
                        print (error)
                    }
                })
            }
            else {
                print (error)
            }

            }

            )}

        else

【问题讨论】:

    标签: swift firebase firebase-authentication


    【解决方案1】:

    试试这个:

    FIREBASE_REF.createUser(email, password: password, withCompletionBlock: {(error) -> Void in
    

    这个块可能只有一个参数

    【讨论】:

      【解决方案2】:

      创建用户有两种选择,一种只是创建它并在失败时返回错误(withCompletionBlock),另一种还返回 authData(withValueCompletionBlock):这就是您想要的。

      myRootRef.createUser(email, password: pw, withValueCompletionBlock: { error, result in
      
                  if error != nil {
                      print("error creating user")
                  } else {
                      let uid = result["uid"] as! String
                      NSUserDefaults.standardUserDefaults().setValue(uid, forKey: "uid")
                      //pass the parameters to another function to auth the user
                      self.authUserWithAuthData( email, password: pw ) 
                  }
      
              })
      

      【讨论】:

        猜你喜欢
        • 2014-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-03
        • 2020-05-26
        • 1970-01-01
        • 1970-01-01
        • 2017-02-07
        相关资源
        最近更新 更多