Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift Microsoft通过Firebase登录_Swift_Firebase_Firebase Authentication - Fatal编程技术网

Swift Microsoft通过Firebase登录

Swift Microsoft通过Firebase登录,swift,firebase,firebase-authentication,Swift,Firebase,Firebase Authentication,我对应用程序开发非常陌生,所以请原谅我。我研究的时间太长了,似乎无法理解如何使用Firebase为Microsoft登录编码我的登录按钮。以下是我目前的代码: import UIKit import FirebaseAuth class LoginViewController: UIViewController { var ref : DatabaseAuth! override func viewDidLoad() { super.viewDidLoad(

我对应用程序开发非常陌生,所以请原谅我。我研究的时间太长了,似乎无法理解如何使用Firebase为Microsoft登录编码我的登录按钮。以下是我目前的代码:

import UIKit
import FirebaseAuth

class LoginViewController: UIViewController {

    var ref : DatabaseAuth!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

    }


    @IBAction func logIntapped(_ sender: Any) {

        let provider = OAuthProvider(providerID: "microsoft.com")
        provider.getCredentialWith(nil) { (credential, error) in
            if error != nil {
                // Handle error.
                print("Failed to retreive credential.")
                return
            }
            if credential != nil {
                Auth.auth().signIn(with:completion:)(<#AuthCredential#>) { authResult, error in
                    if error != nil {
                        // Handle error.
                    }
                }
            } else {
                print("Credential is nil.")
            }
        }
    }
}
导入UIKit
导入FirebaseAuth
类LoginViewController:UIViewController{
var-ref:DatabaseAuth!
重写func viewDidLoad(){
super.viewDidLoad()
//加载视图后执行任何其他设置。
}
@iAction func登录标记(\发送方:任何){
let provider=OAuthProvider(providerID:“microsoft.com”)
中的provider.getCredentialWith(nil){(凭证,错误)
如果错误!=nil{
//处理错误。
打印(“检索凭据失败”)
返回
}
如果凭证!=nil{
Auth.Auth().signIn(带:完成:)(){authResult,中有错误
如果错误!=nil{
//处理错误。
}
}
}否则{
打印(“凭证为零”)
}
}
}
}

您需要将从Microsoft获得的凭据传递到您对Firebase身份验证的呼叫中。比如:

Auth.auth().signIn(with: credential) { authResult, error in
  ...
另请参阅上的Firebase文档