In the iPhone Timer app,
In which the timer should work in the background.
So, I set the notification in appdelegate, it works fine ... In doing so, I call the methods from the view controller that enliven the timer.
Look at some code ...
Application delegate
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@"Time Remaining %d",(self.viewController.totalSeconds-self.viewController.totalCount));
[self.viewController selectandnotify:(self.viewController.totalSeconds-self.viewController.totalCount)];
[self.viewController stopTimer];
[self.viewController startTimerAction];
}
Here I call the startTimerAction method , which is in my view controller ... take a look at this ...
-(void)startTimerAction
{
timer_main = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(ShowActicity) userInfo:nil repeats:YES];
}
What is NSTimer
Here every time
- The ShowActivity method will be called every second ... What's lower in my view controller ...
-(void)ShowActicity
{
NSLog(@"Total Counts %d",totalCount);
if (totalCount == totalSeconds) {
if ([timer_main isValid]) {
[timer_main invalidate];
isTimeOver = YES;
[self generateLog];
}
} else {
totalCount++;
seconds =seconds + 1;
if(seconds > 59)
{
minutes = minutes + 1;
seconds= 0;
}
}
How to call every time This method from the view controller ...
, , ?
... ,