我的iOS应用程序使用firebase时出现问题。我使用以下代码退出:
@IBAction func logoutDidTap(_ sender: Any) {
try! FIRAuth.auth()?.signOut()
虽然app UI反映了signOut,但我收到以下控制台消息: [Firebase /数据库] [I-RDB03812] / media的监听器失败:permission_denied 此外,当我使用不同的用户凭据登录时,该应用程序将以旧用户身份登录。
override func viewDidAppear(_ animated: Bool) {
//user logged in?
FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
if let user = user { //signed in
DatabaseReference.users(uid: user.uid).reference().observeSingleEvent(of: .value, with: { (snapshot) in
if let userDict = snapshot.value as? [String: Any] {
self.currentUser = User(dictionary: userDict)
}
})
}else {
self.performSegue(withIdentifier: Storyboard.showWelcome, sender: nil)
}
})
有什么想法吗?
答案 0 :(得分:0)
我不知道它是否有帮助,但我所做的是在AppDelegate中添加addStateDidChangeListener以检查当前用户是否已登录。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
handle = FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
if FIRAuth.auth()?.currentUser != nil{
// go to main screen if there is a user logged in
}else{
//go to login screen
}
})
return true
}
答案 1 :(得分:0)
我在didFinishLaunchingWithOptions
下将此代码添加到AppDelegate中。如果用户已登录,它会跳过viewcontroller。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
// MARK: Skip splash screen and login, if user is logged in
storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let currentUser = FIRAuth.auth()?.currentUser
if currentUser != currentUser
{
self.window?.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController")
}
else
{
self.window?.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "ViewController")
}
return true
}