开发者

iphone app how to get around timer pausing when app is closed?

开发者 https://www.devze.com 2023-03-08 10:05 出处:网络
at the moment i am using a tim开发者_JAVA百科er to perform a calculation and then update a label every second but once the iphone app is sent to the background the timer pauses and then resumes upon r

at the moment i am using a tim开发者_JAVA百科er to perform a calculation and then update a label every second but once the iphone app is sent to the background the timer pauses and then resumes upon re-opening... what are my options to get around this so that it seems the timer has not stopped ??

--- at the moment trying to record the time in which the app stops and then reopens, that the difference between those values and add the difference to the label but having no luck :(

ANY HELP IS APPRECIATED !!!


When the app moves to the background (i.e. your app delegate gets the applicationDidEnterBackground: message, or you receive a UIApplicationDidEnterBackgroundNotification notification), just stop the timer. And save the current time, if necessary.

Then when the app is moving to the foreground (i.e. your app delegate gets the applicationWillEnterForeground: message, or you receive a UIApplicationWillEnterForegroundNotification notification), recalculate the the label value from the current time and then restart the timer.

0

精彩评论

暂无评论...
验证码 换一张
取 消