ios - 无法实现 Firebase 匿名身份验证

标签 ios swift firebase firebase-authentication

我正在尝试创建一个按钮,让用户匿名登录到 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.
  }
}

最佳答案

希望对您有所帮助。 :)

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.
    }
 }

关于ios - 无法实现 Firebase 匿名身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42615503/

相关文章:

ios - 将 iPhone 应用程序与 iPad 应用程序连接

ios - 尝试运行迦太基时出错

swift - 如何在 UIPickerView 中加载从 Firestore 检索的数据?

ios - 检测苹果设备型号

ios - 如何快速读取文档目录中的 json 文件?

iphone - 如何将 uibutton 添加到自定义注释 View

ios - 如何隐式设置 UITextView contentSize? ( swift 3/xCode8)

objective-c - 将 swift 的 "forced downcast(as!)"转换为 objective-c

java - Firebase,是否可以将 verifyPhoneNumber 放在 Activity 之外而不将 Activity 引用传递给它?

xcode - 无法找到 `Firebase 的规范