且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测自上次应用程序启动以来是否已重新启动iphone

更新时间:2023-01-25 21:49:07

这似乎可以工作:




  • 最后重新启动,对于这个例子,让我们将它存储在一个变量名为'tslr'(以毫秒为单位的持续时间,我猜,BTW,你怎么得到的?)

  • 获取当前时间,存储在变量'ct'中,例如

  • 计算上次重新启动的时间(我们称之为'lr'),我们有:lr = ct - tslr

  • store'lr'



下次启动应用程序时,请加载'lr'的上一个值, ,如果他们不同,你已经检测到重新启动(你可能要忍受一个小的差异,有几个毫秒可能)。



我认为将非常难以愚弄那个...用户必须非常精确地篡改他们的电话时间,他们必须在非常精确的时刻开始你的应用程序,正是当新的'lr'将是相同的对前一个...很难做,他们能够做到这一点的概率非常接近0我认为。您不需要任何互联网连接就可以做到这一点...



在以下情况下,新的lr将与上一个完全相同: p>


  • 电话未重新启动,时间未更改

  • 时间被篡改,以精确的毫秒开始你的应用程序愚弄你的算法(发生超过ultraslim的可能性)


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?

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)