NSDate Update?

Discussion in 'iOS Programming' started by xArtx, Jul 21, 2012.

  1. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #1
    Hi Guys,
    I was wondering if there is a way to tell when the iPhone last updated it's clock from a server or wherever it gets it from,
    or to tell it to update?
    Cheers, Art.
     
  2. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #2
    There is a notification, NSSystemClockDidChangeNotification, that is posted when the clock changes.

    I don't think there is a way to trigger a time update through code. As far as I know, it gets it from the cell phone system automatically, and if cell service is turned off/unavailable, you can't set the time automatically.

    Disclaimer: This is my understanding, but I could be wrong.
     
  3. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #3
    Thanks for the reply :)
    It would be sufficient for me to know how long since the time was updated,
    so I can work out whether the system time can be relied upon or not,
    but Googling NSSystemClockDidChangeNotification, I don't see any confirmation
    that it responds to auto updates the phone does on it's own.
    There is plenty of posts confirming it responds to the user changing the clock
    manually.
    Are you able to confirm that it detects the automatic updates?
     
  4. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #4
    I assume so, but I do not know for sure.

    I would suggest running a test. Write an app that logs the notification. Put your phone in airplane mode, set the clock to an obviously wrong time, and launch your app. Then take the phone out of airplane mode in a "dead zone" where you can't get signal (like an elevator, or I've used a grounded metal cake tin for this) switch back to your app, and watch for notifications when you leave the "dead zone"
     
  5. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012

Share This Page