This is my data model.
project-foo
-posts
-KLs123412341234
key: "-KLs123412341234"
message: "free cupcakes"
time: 1467675688163
-...
key: "..."
message: "..."
time: ...
I'd like to only fetch posts in the last 15 minutes.
I see in my Firebase Console children being added, but the problem is that the observer doesn't seem to be invoked - "hello"
is not printed.
My iOS app has the following code, which does not get invoked:
class ViewController: UIViewController {
var ref: FIRDatabaseReference?
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
ref!.queryOrderedByChild("time")
.queryStartingAtValue(startTime())
.observeEventType(.ChildAdded, withBlock: { snapshot in
print("hello")
})
}
}
My Android app has the following code, which does get invoked:
Query query = mDatabase.orderByChild("time").startAt((double)startTime());
query.addChildEventListener(new PostListener(this, mMap));
class PostListener implements ChildEventListener {
public PostListener(Context context, GoogleMap map) {
...
}
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.i(TAG, "hello");
...
}
}
Update:
My mistake was not realizing that I had initialized mDatabase
(in the android version) with path posts
. The fix was simply to initialize ref
with FIRDatabase.database().referenceWithPath("posts")
instead of FIRDatabase.database().reference()
.