-1

how do I stop or bypass the auto reload in Firebase Realtime Database, I want to manually reload the data. for instance, I want to use UIRefresh controller instead of using firebase cache reload

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
JohnM
  • 73
  • 7
  • It's not clear what you're trying to do. Please edit the question to show the code that's not working the way you expect, explain what it is actually doing instead, and what you would like to happen that's different that your observations. – Doug Stevenson Dec 31 '19 at 20:00
  • It wasn’t a Piece of non working code, I couldn’t find away to stop the auto reload of firebase. – JohnM Dec 31 '19 at 21:57
  • That still sounds like code that doesn't work the way you expect. Please post all relevant code when posting on Stack Overflow, so we can see what you're working with. – Doug Stevenson Dec 31 '19 at 22:10
  • its alright, I was able to fix it with a boolean, thank for the help though – JohnM Dec 31 '19 at 22:13

1 Answers1

0

If you want to only load data once, and not automatically get notified of changes, you can use the observeSingleEvent methods.

Also see the documentation on reading data once, which contains the following example:

let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
  // Get user value
  let value = snapshot.value as? NSDictionary
  let username = value?["username"] as? String ?? ""
  let user = User(username: username)

 // ...
  }) { (error) in
    print(error.localizedDescription)
}

The above example reads the data of users/$userID once, either from the server or from the local cache. A note on that last aspect: you shouldn't combine observeSingleEvent with enabling disk persistence as they don't work well together as explained in Firebase Offline Capabilities and addListenerForSingleValueEvent

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • though that didn't help. I was able to "bypass" it with as boolean that won't reload the data in the array or table without UIRefreshed controller. thank you for your help though!! – JohnM Dec 31 '19 at 22:11
  • 1
    For future questions, be sure to read [how to create a minimal, complete, verifiable example](http://stackoverflow.com/help/mcve), as it increases the chance that someone can help you. – Frank van Puffelen Dec 31 '19 at 22:15