Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ways of implementing timer in iOS

What are some of the better/best ways of implementing a countdown timer in iOS?

I've done some digging and tried using NSTimers (1 sec timer) but some people suggest that's not a good way because its not very accurate!!! Others claim it wastes battery, since its always going to be on in the background till the time elapses. I was thinking I could create a multiple scheduled NSTimer so it won't loose sync. Some suggest I should record the actual timestamp at the beginning and somehow make use of the built-in clock and use that to update the timer countdown.... except I can't seem to figure out how to do that. Any ideas? How are you implementing it?

like image 240
HM1 Avatar asked Mar 25 '11 17:03

HM1


1 Answers

Any time you are implementing a timer, the best option is always to record your start time. Then, whenever you update your interface, simply take the difference of the current time and your start time. You can then use NSTimers to trigger updates of the interface at certain periods.

like image 200
Kevin Sylvestre Avatar answered Oct 16 '22 05:10

Kevin Sylvestre