【问题标题】:How can I handle offline logout with Firebase in Swift?如何在 Swift 中使用 Firebase 处理离线注销?
【发布时间】:2019-04-17 19:07:35
【问题描述】:

我不确定当用户离线时如何处理我的 IOS 应用程序中的注销。

我在 Swift 中使用 Firebase 进行身份验证,它在在线登录/注销时可以完美运行。但是,我想让用户在离线时注销。目前,当离线并且用户单击注销按钮时,屏幕上没有任何反应。如果我重新启动应用程序,我将进入登录屏幕,就好像发生了注销一样。

do {
   try Auth.auth().signOut()
} catch let signOutError as NSError {
   print (signOutError)
}
self.performSegue(withIdentifier: "unwindToMain", sender: self)

此代码在联机时适用于注销,但在脱机时不执行 segue。我也尝试过将 segue 放在 do and catch 中。

【问题讨论】:

  • 我刚刚尝试过,它似乎对我有用,所以让我们在这里更深入地挖掘一下。能否在 try/catch 块中放置一些断点,以便查看正在执行的代码?

标签: ios swift firebase firebase-authentication


【解决方案1】:

请尝试以下代码

  if Auth.auth().currentUser != nil {
        do {
            try Auth.auth().signOut()
            let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Welcome")
            present(vc, animated: true, completion: nil)

        } catch let error as NSError {
            print(error.localizedDescription)
        }
    }

【讨论】:

  • 这行得通。当我离线并单击注销时,会显示登录 VC。我试图使用 unwind segue 回到登录 VC,以便 VC 以前在屏幕上的内容不再位于内存或堆栈中。如上所述实例化和呈现 vc 是否会从内存中删除以前的 VC?
猜你喜欢
  • 1970-01-01
  • 2021-06-03
  • 1970-01-01
  • 2019-01-16
  • 1970-01-01
  • 2016-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多