iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 使用Firebase和日期过滤器大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个酒店预订应用程序,向用户显示可滑动的日历.现在最终目标是提供一个日历,如接口,每个保留日期下方的小点.现在,我只是试图在控制台上打印开始日期和结束日期之间的所有预约(开始日期和结束日期分别是月份的开始和结束日期).

但是,我无法将其与Firebase配合使用.以下是Firebase上数据的处理方式:

{
  "reservations" : {
    "-KSgRjwpssoZJWjV9ScM" : {
      "checkin" : 1474950600,"checkout" : 1475116200,"customer" : "-KMVMMudWJlFeiimtgJl"
    }
  }
}

这是我的Swift代码检索数据:

private var ref: FIRDatabaseReference!

// viewdidload:
ref = FIRDatabase.database().reference()
ref.keepSynced(true)

// logic to fetch data
DispatchQueue.global().async {

        // BACkground Processing
        // check Firebase for events between startdate and enddate
        print("Fetching Reservations")
        print(startDate.timeIntervalSince1970)
        print(endDate.timeIntervalSince1970)


        self.ref.child("reservations").queryStarTing(atValue: startDate.timeIntervalSince1970,childKey: "checkin").observe(.childAdded,with: { (snapshot) -> Void in

            print("Data Retrv.\n")
            print(snapshot)

        })
}

这是现在打印到控制台上的内容

Fetching Reservations
1469989800.0
1472581800.0
Fetching Reservations
1472668200.0
1475173800.0

由于其清晰可见数据落在第二范围内,但我仍然无法让它显示出来.

这可能有什么问题?谢谢.

解决方法

我试过这个代码,它工作:

let ref = FIRDatabase.database().reference()
let refreservations = ref.child("reservations")

let startDate: Double = 1472668200.0

refreservations
  .queryordered(byChild: "checkin")
  .queryStarTing(atValue: startDatE)
  .observeSingleEvent(of: .value) { (snap: FIRDataSnapshot) in
    print(snap.value)
  }

您的代码和我的代码间的区别是我更多地调用一个查询

.queryordered(byChild: "checkin")
.queryStarTing(atValue: startDatE)

你:

.queryStarTing(atValue: startDate,childKey: "checkin")

大佬总结

以上是大佬教程为你收集整理的ios – 使用Firebase和日期过滤器全部内容,希望文章能够帮你解决ios – 使用Firebase和日期过滤器所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。