yosifz8
yosifz8

Reputation: 561

Determining how much time has passed since the app was used

I am looking to make an app that, after a given time of no use, will close or give a message to the user.

How can I implement this?

Upvotes: 0

Views: 252

Answers (3)

David
David

Reputation: 7303

UKIDleTimer is what you're looking for. You create a timer that only fires when the system becomes idle and implement the following method in its delegate:

-(void) timerBeginsIdling: (id)sender {
    // terminate app
    [NSApp terminate];
}

Upvotes: 1

dawg
dawg

Reputation: 104032

How about:

[NSApp performSelector:@selector(terminate:) 
  withObject:nil 
  afterDelay:[your delay...]];

Upvotes: 0

Jayy
Jayy

Reputation: 14798

Look at various Hello World examples on the net for Objective C. Once you have a hello world example going, you'll want to add some event listeners to monitor user activity. When any of those event handlers are called as a result of a users' actions, they should set a variable with the time of that action. Finally, set up a timer to check for user inactivity, say once every 30 seconds, which checks that value, to see if it's exceeded the time at which you want the application to close. If so, then send an exit command.

Upvotes: 0

Related Questions