English 中文(简体)
iphone应用程序关闭时如何避开定时器暂停?
原标题:iphone app how to get around timer pausing when app is closed?

目前,我正在使用计时器进行计算,然后每秒更新一个标签,但一旦iphone应用程序被发送到后台,计时器就会暂停,然后在重新打开时恢复。。。我有什么选择来解决这个问题,这样计时器似乎就没有停止??

---在试图记录应用程序停止然后重新打开的时间时,这些值之间的差异并将差异添加到标签中,但没有运气:(

感谢您的帮助!!!

问题回答

当应用程序移动到后台时(即,您的应用程序代表收到applicationDidEnterBackground:消息,或者您收到UIApplicationDidEnterBackgroundNotification通知),只需停止计时器。如有必要,请保存当前时间。

然后,当应用程序移动到前台时(即,您的应用程序代表收到applicationWillEnterForeground:消息,或者您收到UIApplicationWillEnterForegroundNotification通知),从当前时间重新计算标签值,然后重新启动计时器。





相关问题
How do I wait for a TTimer to finish?

I have a TFrame (fraDisplay) with a TTimer (timAnimateDataChange). The timer is used to control a small animation. In the form containing the frame I want to have a method that does something like ...

How to tell if an ajax timer has gone off at page_load

I have a web application and I m attempting to put an ajax timer control in it to give me a post back every 10-20 seconds. (possibly longer depending on performance). I have a lot of dynamically ...

Got an error 1120 ~ Access of undefined property

This is not your typical 1120. I know better than to have buttons/MCs without instance names on the timeline. Nope, this problem resides in a I timer I built from script I found online. The undefined ...

what is the right way to call the Timer ElapsedEventHandler

i have a timer that calls its even handler method every 30 seconds. but i want to initialy call this method. the signature of the event handler method is void TimerElapsed_GenerateRunTimes(object ...

Timer for a polling windows service

I wrote a Timer class in order to use it within a windows service that is polling another system. I did this because I had two issues that the System.Timers.Timer is not addressing. The Elapsed ...

Using C# Timer to stop executing a Program

I want a program to stop executing for a certain amount of time. And i want this to happen in regular intervals. For example, i want a program to run for 5 minutes and then it should stop for 2 ...

热门标签