mm24
mm24

Reputation: 9596

Firebase: record server side timestamp (Objective-C)

I am unsure on how to create automatically a time stamp at server side in Firebase.

Here is how I create my record:

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

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

I found this question that suggests the following, however I am unsure how to translate that into Objective-C:

curl -X PUT -d '{"something":"something", "timestamp":{".sv": "timestamp"}}'

How do I translate this into Objective-C?

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

Is this the right approach?

I found also this Q/A in Swift.

Upvotes: 0

Views: 766

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599541

From the Firebase documentation:

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

The onDisconnect part is irrelevant (just happened to be in the sample I copied this from). You're looking for FIRServerValue timestamp.

Upvotes: 3

Related Questions