Most reliable way to get current date online?

Discussion in 'iOS Programming' started by Danneman101, Mar 17, 2012.

  1. Danneman101, Mar 17, 2012
    Last edited: Mar 17, 2012

    Danneman101 macrumors 6502

    Joined:
    Aug 14, 2008
    #1
    What is the most reliable way of getting the current date from an online server in a format you can use easily in ios?

    [edit]
    Maybe I should explain why I don't wish to use for instance:
    Code:
    NSDate *today1 = [NSDate date];
    
    It's simply because I don't intend to allow the user to manipulate that value by changing the date on his/hers device.

    Perhaps it's possible to force the NSDate to be fetched online instead of from the system date?
     
  2. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
  3. chown33, Mar 17, 2012
    Last edited: Mar 17, 2012

    chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    Pretty much any web page has HTTP headers that include the date and time. So simply pick a trusted server (it doesn't even need to be one you own or control), and issue an HTTP request. The headers will contain the date. It doesn't need to be "most reliable". It just needs to be fairly competent and not trivially spoofable.

    Personally, I'd pick a small and simple web page, from a widely accessible service, perhaps something located on the Amazon S3 service, or a Wikipedia page for some small item.

    Of course if you don't have an active internet connection, none of this will work. So you should be thinking about the fallback strategy for what your code will do then. Because if the date matters that much to you, someone will find some other way to trick the app into using some other date.
     
  4. Danneman101 thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #4
    Thanks for your suggestions.

    I found a way that suits me better, however, since I'm using parse.com.

    I simply update an object in the database, and then retrieve the "updatedAt"-value from that object. Works great :)
     

Share This Page