tobeiosdev tobeiosdev - 13 days ago 6
Swift Question

onDisconnectRemoveValue doesn't delete (key: value) after log out firebase?

I am using

FBSDKLoginManager().logOut()
and
try! FIRAuth.auth()!.signOut()
for log out account in Swift. But
onDisconnectRemoveValue
doesn't remove (key: true) from Firebase "online/key" child node. Should I remove this key manually or what's wrong with this case?

Answer

If you CMD+CLICK on onDisconnectRemoveValue you will be navigated to the firebase documentation , :-

  • Ensure the data at this location is removed when
    • the client is disconnected (due to closing the app, navigating to a new page, or network issues).

So when you log out the user the network link to firebase is still alive, you haven't closed your app yet and neither have you navigated to another app leaving your firebase app in background.

So, try using this:-

FIRDatabase.database().reference().child("your_Path").updateChildValues(["online" : false], withCompletionBlock: {(err, ref) in


        if err == nil{

            // Sign out your user

        }
    })