Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS/Firebase:使用queryStartingAtValue和NSDate()。timeIntervalSince1970不返回任何结果_Ios_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

iOS/Firebase:使用queryStartingAtValue和NSDate()。timeIntervalSince1970不返回任何结果

iOS/Firebase:使用queryStartingAtValue和NSDate()。timeIntervalSince1970不返回任何结果,ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,我试图查询具有时间戳的最新对象,该时间戳不是由服务器创建的。不幸的是,在使用NSDate()时,观察者没有按预期触发新消息。即使没有错误消息,timeintervalnce1970: let timestampQueryValue = NSDate().timeIntervalSince1970 * 1000 let messagesRef = self.ref.child("messages").child(chatId) messagesRef .

我试图查询具有时间戳的最新对象,该时间戳不是由服务器创建的。不幸的是,在使用
NSDate()时,观察者没有按预期触发新消息。即使没有错误消息,timeintervalnce1970

    let timestampQueryValue = NSDate().timeIntervalSince1970 * 1000

    let messagesRef = self.ref.child("messages").child(chatId)

    messagesRef
        .queryOrderedByChild("timestamp")
        .queryLimitedToLast(500)
        .queryStartingAtValue(timestampQueryValue) // if commented out, new messages show up alongside older ones
        .observeEventType(.ChildAdded, withBlock: { (snapshot) -> Void in

        // ...
    })

我使用的是
Firebase 3.4.0

当使用
NSDate()时,观察者没有按预期开火。timeIntervalSince1970
NSDate()。timeIntervalSince1970*1000
?当使用
NSDate()时‌​还有,1970*1000
如代码所示。为了确定,对象上是否有
时间戳
字段?好的,我想我找到了原因:由
NSDate()创建的时间戳。timeInterv‌​‌​此外,1970*1000
比服务器时间提前一小时。这就是为什么没有新消息出现的原因。但是在
queryStartingAtValue
中使用
FIRServerValue.timestamp()
会抛出错误。你知道如何处理这个问题吗?