2017-07-03 57 views
-1

我遇到了使用Firebase的iOS應用的問題。我簽署了用下面的代碼:Firebase signOut表現不如預期

 @IBAction func logoutDidTap(_ sender: Any) { 
      try! FIRAuth.auth()?.signOut() 

雖然應用程序UI反映signOut,我收到以下控制檯消息: [火力地堡/數據庫] [I-RDB03812]聆聽者/媒體失敗: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) 
     } 
    }) 

任何想法?

+1

更可能有其中符號出的壓入堆棧和其它聽衆前彈出的狀態。因此該應用正試圖在退出後讀取Firebase節點;因此許可被拒絕。這可能是一種情況,即您擁有頂級觀察員,並且該閉包中發生其他事件,包括註銷功能。 – Jay

+0

您需要回到以前的問題,並將答案標記爲正確或提供反饋。只是提問而不提供反饋給給你答案的人是不好的形式。 – AgRizzo

回答

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 
} 
0

我將此代碼添加到AppDelegate的didFinishLaunchingWithOptions下。它跳過一個的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 
}