【问题标题】:How do I know whether the data is in cache or not in iOS Firebase?我如何知道数据是否在 iOS Firebase 中的缓存中?
【发布时间】:2016-05-23 21:18:56
【问题描述】:

我是 Firebase 的新手。我的 iOS 应用也支持离线功能。我正在使用 Firebase doc for iOS 描述的 Firebase.defaultConfig().persistenceEnabled = true

我如何知道数据是否仍在缓存中。我正在寻找这个问题的答案,但找不到任何答案。

提前致谢。

【问题讨论】:

    标签: ios swift firebase firebase-realtime-database


    【解决方案1】:

    如果 firebase 断开连接,则应缓存数据。检查 firebase 连接状态:

    Firebase *connectedRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/.info/connected"];
    [connectedRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
      if([snapshot.value boolValue]) {
        NSLog(@"connected");
      } else {
        NSLog(@"not connected");
      }
    }];
    

    还有更多信息: https://www.firebase.com/docs/ios/guide/offline-capabilities.html

    【讨论】:

    • 感谢@alphonese qi 的回复。实际上我的问题是,如果我在离线数据同步到 firebase 服务器之前使用 ref.unauth() 注销,所有离线数据都会丢失。无论如何我可以在我 unauth() 之前检查我的离线数据是否同步到 firebase ???
    • firebaser here 目前您的应用程序代码无法检测同步状态。一种解决方法是按照@alphoneseqi 的建议检测连接状态。
    猜你喜欢
    • 2019-06-19
    • 1970-01-01
    • 2016-11-20
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 2019-10-11
    • 2011-07-23
    • 1970-01-01
    相关资源
    最近更新 更多