GeoFire swift 3查询不按GeoFire / FireBase预期的顺序返回结果

时间:2017-01-02 05:50:45

标签: ios swift firebase swift3 geofire

以下是我的ViewController中的相关功能:

<option value= "<?php echo $rows['c_id']?>" id="optin_val" <?php echo (!empty($_COOKIE['dropdown']) && $_COOKIE['dropdown'] == $rows['c_id'] ? 'selected' : ''); ?>><?php echo $rows['city_nm'];?></option>

该操作有效,但响应出现意外顺序。我认为.observeReady调用将返回初始结果集,但它不会立即返回任何内容,并继续执行打印&#34; Done Looking for People&#34;的行。

在获得初始结果集之前,有没有办法让我的功能块?

这是我得到的输出:

@IBAction func findPeople(_ sender: Any) {
    let center = CLLocation(latitude: myLocation.latitude, longitude: myLocation.longitude)
    let radiusQuery = geoFireUserLocations!.query(at: center, withRadius: 0.05)

    print("Start Looking for People")

    _ = radiusQuery!.observe(.keyEntered, with: { (key: String?, location: CLLocation?) in
        print("  ALERT:  Found Someone Close : ",key!)
    })

    _ = radiusQuery?.observeReady({
        print("  All initial data has been loaded and events have been fired!")
    })

    print("Done Looking for People")

    //TODO: Based on the GeoFire result do something smart   
}

我在期待:

Start Looking for People
Done Looking for People
     ALERT:  Found Someone Close :  oSf00ex6SyMAwpF2NRxymyxxx123
        All initial data has been loaded and events have been fired!

如何创建一个阻止功能,直到它从GeoFire获得初始结果?

我想发送请求,获得结果,然后根据结果采取适当的措施。应用程序当前的行为方式似乎并不是让它等待结果的方法。

任何人都可以提供一些有关如何按照我描述的方式进行此项工作的见解和/或建议吗?是否有我可以调用的某种阻塞调用或我可以使用的同步方法,以确保在决定下一个操作之前得到结果?

干杯!

0 个答案:

没有答案