【问题标题】:Sign Out of Firebase in Swift 4 [duplicate]在 Swift 4 中退出 Firebase [重复]
【发布时间】:2020-03-07 11:20:16
【问题描述】:

我想在使用 firebase 登录后从我的应用程序中退出,我在我的应用程序中尝试了此代码,但它不起作用。

print("clickSignOut")
        do {
            try Auth.auth().signOut()
       } catch {
         print("can't signOut")strong text
       }
      print(Auth.auth().currentUser ?? "no user")

【问题讨论】:

  • Firebase 身份验证会话存储在用户钥匙串中,这就是为什么看起来他们仍在使用 print 语句进行身份验证的原因。您需要使用链接问题中的技术手动删除该钥匙串数据。有关一些代码建议,请参阅 this answer

标签: swift xcode firebase compiler-errors logout


【解决方案1】:

这对我总是有效的:

do {
    try Auth.auth().signOut()
} catch let error {
    print("Error: ", error.localizedDescription)
}

如果这对您不起作用,请向我们提供更多背景信息。 “它不起作用”是什么意思?如果您使用提供的此代码,它将告诉您遇到了什么错误。

【讨论】:

  • 我试过了,效果不好
  • 它怎么不起作用?是调用了错误还是没有尝试此 try 行?你能设置一些断点来更好地理解流程吗?
  • 不,当我单击项目栏按钮时,它没有收到错误,但没有注销
  • 能否在按钮的@IBAction 函数中设置断点以确保代码被调用?
  • 非常感谢它现在的工作
【解决方案2】:

检查这是否有帮助:

try! Auth.auth().signOut()

【讨论】:

  • 我试过了,效果不好
  • 你能分享你的代码吗?
  • 当然可以。
  • @IBAction func signOutButtonTapped(_ sender: Any) { do { try Auth.auth().signOut() } catch let error { print("Error: ", error.localizedDescription) }跨度>
  • 不是这个。整个代码都在 GitHub 上吗?
猜你喜欢
  • 2017-03-17
  • 1970-01-01
  • 2016-10-22
  • 2018-10-03
  • 2018-07-15
  • 1970-01-01
  • 2021-10-22
  • 2020-03-13
  • 1970-01-01
相关资源
最近更新 更多