I have a problem with my connection between my app and firebase database. After adding:
Database.database().isPersistenceEnabled = true
To my AppDelegate, some of the data is out of sync. To get my data i use:
self.ref?.child("Stores").observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let store = Store()
store.Latitude = dictionary["Latitude"]?.doubleValue
store.Longitude = dictionary["Longitude"]?.doubleValue
store.Store = dictionary["Store"] as? String
store.Status = dictionary["Status"] as? String
stores.append(store)
DispatchQueue.main.async {
self.performSegue(withIdentifier: "LogInToMain", sender: nil)
}
}
})
And on the next ViewController, i use the date to make annotations on a map. Like this:
func createAnnotation(Latitude:Double, Longitude:Double, Store:String, Status:String) {
let annotation = CustomPointAnnotation()
let latitude: CLLocationDegrees = Latitude
let longitude: CLLocationDegrees = Longitude
annotation.coordinate = CLLocationCoordinate2DMake(latitude, longitude)
annotation.title = Store
annotation.imageName = "\(Status).png"
map.addAnnotation(annotation)
}
But the problem is, that the data to the annotation dont change with the database anymore. The app needs to be opened, then closed, then opened again before the data is shown correctly. Can anyone help with that problem?