【问题标题】:Firebase: record server side timestamp (Objective-C)Firebase:记录服务器端时间戳(Objective-C)
【发布时间】:2016-11-02 04:50:50
【问题描述】:

我不确定如何在 Firebase 的服务器端自动创建时间戳。

这是我创建记录的方式:

NSMutableDictionary * dictionary = [[NSMutableDictionary alloc] init];
NSString * userId = [self determineUserId];

[[[_ref child:@"records"] child:userId] updateChildValues:dictionary];

我发现this question 暗示了以下内容,但我不确定如何将其翻译成 Objective-C:

curl -X PUT -d '{"something":"something", "timestamp":{".sv": “时间戳”}}'

如何将其翻译成 Objective-C?

 "timestamp":{".sv": "timestamp"}

这是正确的方法吗?

我还在 Swift 中找到了这个 Q/A。

【问题讨论】:

    标签: objective-c firebase timestamp record firebase-realtime-database


    【解决方案1】:

    来自Firebase documentation

    FIRDatabaseReference *userLastOnlineRef = [[FIRDatabase database] referenceWithPath:@"users/joe/lastOnline"];
    [userLastOnlineRef onDisconnectSetValue:[FIRServerValue timestamp]];
    

    onDisconnect 部分无关紧要(恰好在我从中复制的示例中)。你正在寻找FIRServerValue timestamp

    【讨论】:

    • 您好弗兰克,感谢您的回复。我觉得这很混乱。之前的文档没有提到“onDisconnect”阶段。我要做的就是保存值实际写入服务器的时间戳。那么这里的方法为什么要和onDisconnect结合使用呢?
    • 不需要onDisconnect。我只是碰巧从那个样本中复制了它。您只需要FIRServerValue timestamp 来自firebase.google.com/docs/reference/ios/firebasedatabase/…
    • 谢谢。您能否更新答案,以便我可以接受它作为最终答案?成功了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 2020-05-03
    • 2018-11-27
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多