I’ve got a program in which I want to code a timer which checks wether the user is idle or not. For that I wrote following code:
if (!idleTimer) {
NSLog(@"make");
idleTimer=[[NSTimer alloc]initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:10.0]interval:10 target:self selector:@selector(idleTimerExceeded) userInfo:nil repeats:NO];
NSLog(@"madetimer with: %f, %@", idleTimer.timeInterval, idleTimer.fireDate);
}else {
NSLog(@"no reset timer: %f", idleTimer.timeInterval);
if (fabs([idleTimer.fireDate timeIntervalSinceNow]) < 9) {
NSLog(@"reset");
[idleTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:10]];
}
}
But somehow my logs show that the interval is always 0.0000 . Which means that something is wrong here. Can anybody help me?
ive never seen a timer look so complicated. try this:
write a method that checks if the user is idle (lets say idleChecker)
then make the timer repeatable and calls that method idleChecker
remember to declare the idleChecker method in the .h file
take note if u want to stop the timer event then you need to maintain a reference to it
then to stop it
as for checking if its running i would just stick a nslog message in there stating something like “check for idle user”