开发者

Saving NSTimer to NSUserDefaults

I'm doing a s开发者_如何学Pythonimple 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?


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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜