Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect whether the iphone has been rebooted since last time app started

I'd like to detect from within my app whether the iPhone has been rebooted since last time my app was started. I need to do this because my app uses the timer since last system reboot to clock a user's time and I want to detect reboot so I can invalidate the time.

Is there anywhere I could extract the information from the system console log like reboot , crashes ? The organizer in xcode can access it , maybe I can too.

If not , can you think of other ways to get this information?

like image 406
Maxm007 Avatar asked Sep 18 '09 10:09

Maxm007


Video Answer


2 Answers

This seems like it would work:

  • get the time since last reboot, and for this example, let's store it in a variable called 'tslr' (duration in milliseconds I guess, BTW, how do you get that?)
  • get the current time, store it in variable 'ct' for example
  • compute the last reboot time (let's call it 'lr'), we have: lr = ct - tslr
  • store 'lr'

Next time your application gets started, load the previous value for 'lr', compute the new one, and if they differ, you have detected a reboot (you'll probably have to tolerate a small difference there... a couple milliseconds perhaps).

I think it would be pretty tough to fool that... the user would have to tamper their phone time very precisely, and they would have to start your application at a very precise moment on top of that, exactly when the new 'lr' would be identical to the previous one... pretty tough to do, the probability of them being able to do that is very close to 0 I think. And you don't need any internet connection to do that...

The new 'lr' would be identical to the previous one in the following cases only:

  • phone was not rebooted, and time was not changed
  • time was tampered with, AND the user managed to start your application at the precise millisecond to fool your algorithm (chances of that happening more than ultraslim)
like image 63
Zoran Simic Avatar answered Oct 13 '22 09:10

Zoran Simic


Zoran's answer is the right way to go; it's the closest you are going to get without a network connection. (neither the cellular subsystem, nor the syslog are accessible for security reasons)

If you are looking to prevent malicious users from generating fake time data, have some central server (or trusted local server for enterprise deployments) track time-related events for you.

like image 38
rpetrich Avatar answered Oct 13 '22 07:10

rpetrich