I'm doing a simple game for the iPhone and now that is finished, I'd like to add a timer. I managed to implement the timer, but now I want to pause it when an incoming SMS or Phone Call minimize the application. I thought that I should put the timer in the app delegate and, when applicationWillResignActive/applicationDidBecomeActive will be called, save/restore the timer object with NSUserDefaults, but I see that I can only save "raw" data, not entire objects. How can i manage this trouble?
Asked
Active
Viewed 541 times
1 Answers
0
You'll need to store the elapsed time in a variable (I wouldn't use NSUserDefaults) and then create a new timer with the elapsed time subtracted.
See this question for some more info: How can I programmatically pause an NSTimer?
-
Maybe I coded wrong, but basically I don't need the state itself of the timer but to launch the selector in the subview to refresh a UILabel... – IssamTP Nov 10 '10 at 10:03
-
I'm sorry but I don't understand what you mean. I thought you wanted to 'pauze' a NSTimer on `applicationWillResignActive` and 'start' it again on `applicationDidBecomeActive`. Is this correct? – Rengers Nov 10 '10 at 13:41
-
Yes, but I don't need the "value" itself, just the "repetitions". Anyway I guess I've solved the matter in another way. – IssamTP Nov 17 '10 at 14:06