I want to know if it is possible to delete an item in the firebase database through database rules or something server side. Right now I am using client side app to delete values from firebase after a timer is reached. I want to avoid using client side for deletion of the item as I do not want multiple users to try to delete the items from the database.
Second I want to know if there is way to make a unique observers query in firebase where I only get new data instead of querying all the old data. I have it setup with a map where as something is added it queries for that data and adds it to the map. However it is giving me all of the data from the database and causing multiple additions of annotations on my mapview. Now I can remove the annotations before they are added, but that is very hacky and not User friendly.
Code:
class FBService {
static let instance = FBService()
var firRef: FirDatabaseReference!
private init() {
self.fireRef = FIRDatabase.database().reference()
}
fun getMyAnnotations(location: CLLocation, completion: ([annotationLocation]? -> ())) {
let now = NSDate().timeIntervalSince1970
let locationRef = fireRef.child("annotations").queryOrderedByChild("timestamp").queryStartingAtValue(now)
// Before I was doing fireRef.Child("annotations").queryOrderedByChild("latitude")
locationRef.observeEventType(.Value) { (snapshot) in
completion(self.someMethod(snapshot))
}
}
func someMethod(snapshot: FIRDataSnapshot) {}
}
class MainVC: UIViewController {
override func viewDidLoad() {
FBService.instance.getMyAnnotations(userLocation) { (annotations) in
if let annotations = annotations {
// Before I was doing mapView.removeAnnotations(mapView.annotations), which removes annotations and re-plops them as they come back.
for anno in annotations {
let pin = CustomAnnotation(coordinate: CLLocationCoordinate2DMake(anno.location.latitude, anno.location.longitude), name: anno.name)
mapView.addAnnotation(anno)
}
}
}
}
}