Ios 无法实现Firebase匿名身份验证
我正在尝试创建一个按钮,该按钮将用户匿名登录到Firebase,接收回调,然后如果登录成功,则转换到下一个ViewController。对编程来说非常陌生,因此非常感谢您的帮助:Ios 无法实现Firebase匿名身份验证,ios,swift,firebase,firebase-authentication,Ios,Swift,Firebase,Firebase Authentication,我正在尝试创建一个按钮,该按钮将用户匿名登录到Firebase,接收回调,然后如果登录成功,则转换到下一个ViewController。对编程来说非常陌生,因此非常感谢您的帮助: import UIKit import FirebaseAuth class ViewController: UIViewController { @IBAction func Auth(_ sender: Any) { FIRAuth.auth()?.signInAnonymously(complet
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.
}
}
导入UIKit
导入FirebaseAuth
类ViewController:UIViewController{
@iAction func Auth(\发送方:任意){
FIRAuth.auth()?.signinanoymous(完成:Void#>)
//接收显示完成或错误的回调,然后导航到下一个ViewController
}
重写func viewDidLoad(){
super.viewDidLoad()
//加载视图后,通常从nib执行任何其他设置。
}
重写函数didReceiveMemoryWarning(){
超级。我收到了记忆警告()
//处置所有可以重新创建的资源。
}
}
希望这有帮助。:)
导入,
FirebaseAuth
Auth.auth().signInAnonymously() { (user, error) in
if let aUser = user {
//Do something cool!
}
}
看起来它可能已经工作了,但是当我搜索它时,该方法没有填充用户、错误参数。为什么?嗨,你可以监听身份验证状态
let handle=FIRAuth.auth()?.addStateDidChangeListener(){(auth,user)in//…}
Auth.auth().signInAnonymously() { (user, error) in
if let aUser = user {
//Do something cool!
}
}