开发者

Determining how much time has passed since the app was used

开发者 https://www.devze.com 2023-03-03 11:10 出处:网络
I am looking to make an app that, after a given time of no use, will close or 开发者_如何学Gogive a message to the user.

I am looking to make an app that, after a given time of no use, will close or 开发者_如何学Gogive a message to the user.

How can I implement this?


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];
}


How about:

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消