【发布时间】:2017-12-24 01:22:37
【问题描述】:
我正在使用 GeoFire 并尝试仅获取 3 个满足某些条件的结果。这是我的情况,它不会阻止观察者。有数千个结果,我得到了所有结果,但我只需要 3 个。我基于 this answer 但它在我的情况下不起作用,如您所见。 请问有人可以帮忙吗?
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
ids += 1
if (ids >= 3) {
self.gFCircleQuery?.removeObserver(withFirebaseHandle: self.newRefHandle!)
completion()
}
})
gFCircleQuery?.observeReady({
completion()
})
}
请不要介意 Optionals(?) 这只是为了这个示例代码
来自 GoeFire 文档:
要取消地理查询的一个或所有回调,请调用 removeObserverWithFirebaseHandle: 或 removeAllObservers:, 分别。
两者都不工作。
【问题讨论】:
标签: ios swift firebase firebase-realtime-database geofire