I am able to display the current time on my iPad application using the code,
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle: NSDateFormatterShortStyle];
NSString *currentTime = [dateFormatter stringFromDate: [NSDate date]];
timeLabel.text = currentTime;
But this gives the time only when the application is loaded. How do i get the time to keep running? Like a digital clock.
Implement an NSTimer
How do I use NSTimer?
Then implement the targetMethod to check for and update your time!!!
If it were me, I would probably get the initial time, and only update my internal time using a 1 second timer.
You can go for higher timing resolution by implementing a faster timer (lets say 4 to 8 times faster), with this you will probably not get out of sync very often, but if you did, then you would be able to re-synchronize to the time returned by [NSData date]. In other words the faster your background task runs, the easier it would be for you to re-sync with the true time returned. This would also mean that you would only check for syncronization once out of every couple of times inside your target method.
Guess what Im saying is to remember Nyquist. Nyquist's theory (essentially) states that you should sample at least twice as fast as the resolution that you will ultimately try to reproduce using the dataset obtained from your sampling. In this case if you are trying to display to the user a once per second update, then you really should be sampling at no slower then 1/2 of a second to try and catch the transition from one second state to the next.
Note :- Declare in .h file
Note :- Declare in .m file
//Here assign (tick) Method
Use this:
Selector method would be like this: