2017-03-05 53 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 // ... } –