ObserveSingleEvent returns old data

Viewed 1595

I want to fetch the required app version number when the app starts. But I can't get the right key.

I have this code to fetch. I use observe single event because I use this method to check the required app version number. This method is only fired when the app starts to do the check.

func getVersion(completionHandler: @escaping (Result<Any?>) -> ()) {

     let ref: DatabaseReference! = Database.database().reference().child("version").child("IOS")

     ref?.observeSingleEvent(of: .value , with: { snapshot in

         if snapshot.exists() {    
            let recent = snapshot.value as!  NSDictionary  
            print(recent)
         }
     })
}

But it is returning old results? I have isPersistenceEnabled enabled at my Appdelegate.

This is the database structure:

enter image description here

I get no results when I use Database.database().reference().child("version").child("IOS"). snapshot.exists is false when I use that.

What I previously had was: - version | IOS - 1.0

And i get result when I use Database.database().reference().child("version"), namely {iOS => 1.0}. I don't get it because it was my old structure.

2 Answers
Related