Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
Swift - GeoFire removeObserver Not Working, seeking for workaround please

I find out that both removeObserver and .removeAllObservers() is not working in GeoFire, hoping another work around to "get out" of this observe (which keeps loading forever)

var newRefHandle: FIRDatabaseHandle?
var gFCircleQuery: GFCircleQuery?

func findFUsersInOnePath(location: CLLocation,
                         radius: Int,
                         indexPath: String,
                         completion: @escaping () -> ()){
    var ids = 0
    let geofireRef = usersRef.child(indexPath)
    if let geoFire = GeoFire(firebaseRef: geofireRef) {
        gFCircleQuery = geoFire.query(at: location, withRadius: Double(radius))
        newRefHandle = gFCircleQuery?.observe(.keyEntered, with: { (key, location) in
            // if key fit some condition then perform some other firebase call to other database(async), afterwards:
            ids += 1
            if (ids >= 3) {
                //RemoveObersver not working below...
                self.gFCircleQuery?.removeObserver(withFirebaseHandle: self.newRefHandle!)
                completion()
            }
        })
        //I find that observeReady gets call right away despite we haven't complete  code above 
        gFCircleQuery?.observeReady({
            completion()
        })
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

My guess is that you're still getting some .keyEntered events after the call to removeObserver, which is actually to be expected.

GeoFire performs a single query to get all keys within the range for your query, and then calls your .keyEntered callback for each of these keys. Even if you call removeObserver for the first key, GeoFire will continue to call the .keyEntered callback with the remainder of the keys that it already got from the database.

For this reason, I'd recommend removing the observer inside the ready block for the query. The behavior will not change when you do that, but it'll make more sense as that ready block is called when GeoFire is done telling you about the batch of keys.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda