2017-03-05 66 views
0

我正尝试创建一个按钮,以匿名方式向Firebase中签名用户,接收回调,然后如果登录成功转换到下一个ViewController。非常新的编程,所以任何帮助表示赞赏:无法实现Firebase匿名身份验证

import UIKit 
import FirebaseAuth 

class ViewController: UIViewController { 


@IBAction func Auth(_ sender: Any) { 
    FIRAuth.auth()?.signInAnonymously(completion: <#T##FIRAuthResultCallback?##FIRAuthResultCallback?##(FIRUser?, Error?) -> Void#>) 

     //Receive callback showing completion or error, then navigate to next ViewController 

} 


override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
    } 
} 

回答

1

希望这种帮助。 :)

import UIKit 
import FirebaseAuth 

class ViewController: UIViewController { 

    @IBAction func Auth(_ sender: Any) { 
     FIRAuth.auth()?.signInAnonymously { (user, error) in 
      if let error = error { 
      print("Sign in failed:", error.localizedDescription) 

      } else { 
      print ("Signed in with uid:", user!.uid) 
      } 
     } 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 
} 
+0

看起来它可能已经工作,但是,当我搜索它时,该方法没有填充用户,错误参数。这是为什么? – tccpg288

+0

嗨,您可以侦听身份验证状态。 'let handle = FIRAuth.auth()?. addStateDidChangeListener(){(auth,user)in // ... } –