I needed to implement an inactivity timer in my Cocoa App and did so
my subclassing NSApplication and overriding sendEvent: to start and
stop a timer. Although it works most of the time, every once in a
while my timer gets fired as I'm typing text into a text field or
interacting with some other control like scrolling a table view.
The relevant code in my NSApplication subclass is shown below. I'd
appreciate it if anyone has any insights as to why it isn't working.
#pragma mark -
#pragma mark Inactivity Timer
- (void)sendEvent:(NSEvent *)event
{
[self stopTimer];
[super sendEvent:event];
[self startTimer];
}
- (void)timerExpired:(NSTimer *)timer
{
[[NSApp delegate] performSelector:@selector(timerDidExpire)
withObject:nil afterDelay:0.0];
}
- (void)startTimer
{
// Have timer go off in 15 minutes
inactivityTimer = [NSTimer scheduledTimerWithTimeInterval:(15 * 60)
target:self
selector:@selector(timerExpired:)
userInfo:nil
repeats:NO];
[inactivityTimer retain];
}
- (void)stopTimer
{
if ( inactivityTimer == nil )
return;
[inactivityTimer invalidate];
[inactivityTimer release], inactivityTimer = nil;
}
- Kevin
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com