开发者

Saving NSTimer to NSUserDefaults

开发者 https://www.devze.com 2023-01-24 07:40 出处:网络
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 Phon

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

精彩评论

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

关注公众号