如何检测自上次应用程序启动以来是否已重新启动iphone [英] How can I detect whether the iphone has been rebooted since last time app started

查看:157
本文介绍了如何检测自上次应用程序启动以来是否已重新启动iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的应用程式中侦测iPhone是否自上次应用程式启动以来已重新启动。我需要这样做,因为我的应用程序使用计时器,因为上次系统重新启动时钟用户的时间,我想检测重新启动,所以我可以使时间无效。



在任何地方,我可以从系统控制台日志中提取信息,如重新启动,崩溃?



如果没有,你能想出其他方法来获取这些信息吗?

解决方案

这似乎可以工作:




  • 最后重新启动,对于这个例子,让我们将它存储在一个变量名为'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)

这篇关于如何检测自上次应用程序启动以来是否已重新启动iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆