0

I would like to know what is the best way of working with dates in IOS with a Firebase back-end.

In my App, I've got events and users are allowed to post data until a specific datetime. How can I prevent the user of modifying his system date to be able to do changes to the events while it should not be possible?? How do we typically prevent these cases in iOS? I now that we could work with the timestamp from Firebase, but it is a bit annoying to request the timestamp each time you need to work with dates..

Thanks for the help,

Henry

user3900157
  • 239
  • 1
  • 7
  • 17

2 Answers2

3

If you have a use-case where the client-side timestamp is not good/safe enough, you can always use Firebase's server-side timestamp mechanism.

From the documentation:

Firebase servers provide a mechanism to insert timestamps generated on the server as data. This feature, combined with onDisconnect, provides an easy way to reliably make note of the time at which a client disconnected:

var userLastOnlineRef = Firebase(url:"https://<YOUR-FIREBASE-APP>.firebaseio.com/users/joe/lastOnline")
userLastOnlineRef.onDisconnectSetValue([".sv": "timestamp"])

You can also use the now variable in your security rules, to ensure that the timestamp field is the same as (or at least not after) now.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks. Can this "timestamp" value be used in query or when you insert value. E.g.: `ref.childByAppendingPath("users/joe/updatedAt").setValue("timestamp")` ? – user3900157 Mar 03 '16 at 15:39
  • Yes. http://stackoverflow.com/questions/25536547/how-do-i-get-a-server-timestamp-from-firebases-ios-api – Frank van Puffelen Mar 03 '16 at 15:41
0

If you soley rely on the client's clocks and cannot check them with a server, you may implement a consensus protocol that allows other clients to verify a timestamp/post before it gets accepted.

Tobi Nary
  • 4,566
  • 4
  • 30
  • 50