swift - 在 Swift 中退出 Firebase

标签 swift firebase-authentication

我正在尝试退出 Firebase API,但我似乎无法弄清楚如何处理可能发生的任何错误。

Firebase pod 提供了一种注销方法:

FIRAuth.auth()?.signOut()

它被标记为throws,所以我将它包装在do/try/catch block 中在测试退出过程的方法中:

do {
    try FIRAuth.auth()?.signOut()
} catch (let error) {
    print((error as NSError).code)
}

我看到 signOut 方法在 Firebase pod 中用 throws 标记,但我看不到它如何异步处理任何错误。我已经尝试进入飞行模式,这会在发生网络请求的其他任何地方触发我的代码中的网络错误,但是使用 signOut 方法,该错误没有被捕获,因为我没有完成处理程序从执行。来自 Firebase pod 的所有其他身份验证方法都有一个完成处理程序,我可以在其中处理错误。

这是 Firebase pod 中 signOut 方法的文档:

/** @fn signOut:
    @brief Signs out the current user.
    @param error Optionally; if an error occurs, upon return contains an NSError object that
        describes the problem; is nil otherwise.
    @return @YES when the sign out request was successful. @NO otherwise.
    @remarks Possible error codes:
        - @c FIRAuthErrorCodeKeychainError Indicates an error occurred when accessing the keychain.
            The @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo dictionary
            will contain more information about the error encountered.
 */
open func signOut() throws

当我没有允许我检查错误的完成处理程序时,对于处理用户注销的适当方法,您有什么建议吗?

最佳答案

你可以像这样捕获错误

do
{
     try Auth.auth().signOut()
}
catch let error as NSError
{
     print(error.localizedDescription)
}

关于swift - 在 Swift 中退出 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40402413/

相关文章:

ios - 使用相同背景图像的具有多个场景的 View Controller (UIViewController) Storyboard

javascript - Firebase 身份验证和 Google 登录

android - 运行 Flutter 身份验证时出现黑屏

javascript - Firebase 重新验证社交提供商

swift - 为 Alamofire 和 Argo 创建响应式扩展

Swift 4 编程语言,inout 参数不适用于函数类型作为参数

ios - 什么是最有效的保存和加载静态字符串列表

ios - 谷歌地图 iOS myLocation

java - android google登录后如何初始化firebase?

firebase-authentication - 方法 'signInWithCredential' 未定义