如何在 iOS Swift 中实现 Firebase Microsoft OAuth



我对 Swift 和 Firebase 相当陌生,我正在尝试让 Microsoft OAuth 提供程序按如下所述工作:

https://firebase.google.com/docs/auth/ios/microsoft-oauth?authuser=0

我的应用程序在运行时是稳定的,但 MSLoginTap 按钮没有任何作用,调试时我只能看到provider.getCredentialWith似乎没有运行,因为我没有收到我的打印语句。

文档中似乎有多个错误,因此我尽可能修改它并提交了审查文档的请求。

Firebase 文档代码段:

provider.getCredentialWithUIDelegate(nil) { credential, error in
    if error != nil {
        // Handle error.
    }
    if credential != nil {
        Auth().signInAndRetrieveData(with: credential) { authResult, error in
            if error != nil {
                // Handle error.
            }
            // User is signed in.
            // IdP data available in authResult.additionalUserInfo.profile.
            // OAuth access token can also be retrieved:
            // credential.accessToken
        }
    }
}

问题 1:无法识别provider.getCredentialWithUIDelegate

问题 2:无法识别Auth().signInAndRetrieveData

====

======= ============ ============ ==============

这是我正在使用的内容(不起作用(:

class LoginViewController: UIViewController {
    var ref : DatabaseReference!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    @IBAction func MSLoginTapped(_ sender: UIButton) {
        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().signInAndRetrieveData(with: credential!) { authResult, error in
                    if error != nil {
                        // Handle error.
                    }
                    // User is signed in.
                    // IdP data available in authResult.additionalUserInfo.profile.
                    // OAuth access token can also be retrieved:
                    // credential.accessToken
                }
            } else {
                print("Credential is nil.")
            }
        }
    }
}
遇到了

同样的问题。let provider = OAuthProvider(providerID: "microsoft.com"(

provider 是一个局部变量,getCredentialWith 是异步的,ARC 将摆脱提供者。使其成为全球范围。

Firebase 在 Swift/iOS 中未显示 microsoft.com 的标志页面

最新更新