objective c - Is it possible to save the state of a timer in the User Defaults? -


I have a label on which I am showing the countdown timer

Now if I have my app If I close, the timer will be shut down and the label will be the text too. I know that we can save the label's text value. But when the app starts again, we show the correct countdown.

Suppose I'm close. After 3 minutes when the app is launched the label should be shown. 00:02:35 And the timer should be for the remaining countdown

Yes, just store that time On which your app closes and the time left in the NSUserDefaults to calculate when the app starts again, you get the time when it was closed NSUserDefaults and time remaining. Using the present time is the simple math to calculate the right time on your math.

Something like this can happen, definitely not ignored:

  // save state NSUserDefaults * userDefaults = [NSUserDefaults standard user default]; NSDT * now = [NSDT date]; Double count = 45.0; In // seconds, get it from your counter [userDefaults set object: for now that: @ "timeoutquit"]; [Set UserDefaultsDouble: Countdown to that: @ "Countdown"]; [User default synchronize]; // Restored state NSUserDefaults * userDefaults = [NSUserDefaults standard user default]; NSDate * timeAtQuit = [userDefaults ObjectFire: @ "TimeAutquite"]; Double timecinsquat = [timeout timeInternationalScience]; Double countdown = timeSinceQuit + [userDefaults doubleForKey: @ "countdown"];  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -