开发者

How to capture application inactivity Time in iphone

In my application i want to set inactivity timeout (IdleTime).

How can i set this?

Is there any way to monitor all events in myappdelegate?

For eg i have two UIViewController classes.

when i c开发者_运维知识库lick one control in UIViewController1 or UIViewController2 it should be monitored by myappdelegate


To monitor all user interaction events in application you can use UIWindow subclass. Implement sendEvent: method in it:

- (void)sendEvent:(UIEvent*)event {
    [super sendEvent:event];
        // Process event or just reset inactivity time
}

To use it in your application you need to open application main xib (e.g. MainWindow.xib) and set custom type for UIWindow instance there.


I would probably build a singleton object to monitor it. Putting that functionality with a view or window is semantically muddy.

The class could be called "EventTracker" or something.

It's interface could be very simple:

-(int)secondsSinceLastActivity

-(void)resetActivityTimer

-(EventTracker *)instance

Anywhere in your app, you could call [EventTracker instance] to get the single object, and check time or reset the time.

This will allow for the most expandability down the line.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜