我正在尝试退出 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/