title: NSDate: Get precise time independent of device clock?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7122216/how-can-i-locally-detect-iphone-clock-advancement-by-a-user-between-app-runs">How can I locally detect iPhone clock advancement by a user between app runs?</a><br>
    <a href="https://stackoverflow.com/questions/12006245/is-there-a-way-to-determine-the-actual-time-and-date-in-ios-not-the-time-of-the">Is there a way to determine the actual time and date in iOS (not the time of the device)</a><br>
    <a href="https://stackoverflow.com/questions/11413616/is-there-a-clock-in-ios-that-can-be-used-that-cannot-be-changed-by-the-user">Is there a clock in iOS that can be used that cannot be changed by the user</a></p>
  </blockquote>
  
  
  
  <h2><strong>Brief</strong></h2>
  
  <p>I am working with an auto-renewable subscription-based app. When the app receives the latest receipt from Apple, it stores the <code>expires_date_ms</code> key in <code>NSUserDefaults</code>. Thirty days after that date, the app checks with Apple to see if the subscription is still active. The app can be considered an offline app, but it must connect to the internet once every 30 days in order to check the subscription status. This time comparison will be used to tell the user he/she must connect.</p>
  
  <h2><strong>Problem</strong></h2>
  
  <p>I am using the code below to compare the current time with the <code>expires_date_ms</code>:</p>
  
  <pre><code>NSTimeInterval expDateMS = [[productInfo objectForKey:@"expires_date_ms"] doubleValue];
  NSTimeInterval currentDateMS = ([[NSDate date] timeIntervalSince1970] * 1000);
  
  if (currentDateMS &gt; expDateMS)
      subExpired = YES;
  </code></pre>
  
  <p>This is fine and works well, but from what I can tell there's a loophole that can be exploited - if the user sets the device's clock back a hour/month/decade, the time comparison will become unreliable because <code>[NSDate date]</code> uses the device's current time (please correct me if I'm wrong).</p>
  
  <h2><strong>Question</strong></h2>
  
  <p>Is there any way of retrieving a device-independent time in milliseconds? One that can be accurately and reliably measured with no regards to the device clock?</p>