我正在尝试创建一个按钮,匿名向Firebase签名,接收回调,然后如果登录成功转换到下一个ViewController。非常新的编程,所以任何帮助表示赞赏:
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.
}
}
答案 0 :(得分: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.
}
}
答案 1 :(得分:0)
导入,FirebaseAuth
Auth.auth().signInAnonymously() { (user, error) in
if let aUser = user {
//Do something cool!
}
}