views:

31

answers:

2

Hi All, Im just wondering if there is any method of catching any user interaction with the application.

The reason i ask is that when a user interacts with the app i update a date in the db. if they date is older than 10 minutes they are seen as offline by other users until they comeback and interact with the program.

Does anybody have any ideas on how i could catch any user interaction to update this field?

Thanks

p.s. it is a navigation app. so even if i can add a handler to the navigation controller to say when a page is changed that might do???

+1  A: 

The most convenient way would probably be to subclass UIApplication and override the sendAction:to:from:forEvent: method. You will also need to add a key to your Info.plist file called “NSPrincipalClass” with a string value containing the name of your subclass, which tells UIKit to your subclass in place of UIApplication.

MyApplication.m:

- (BOOL)sendAction:(SEL)action to:(id)target
        from:(id)sender forEvent:(UIEvent *)event
{
   ResetInterationTimeout();

   return [super sendAction:action to:target from:sender forEvent:event];
}

Info.plist:

<key>NSPrincipalClass</key>
<string>MyApplication</string>
Todd Yandell
A: 

If by interaction you mean 'touches' then you can easily do that by putting a UIView (if do not have a global one on top of the others) on each UIViewController in your NavigationController that has the duty of registering a touch, saving the current date to an higher level controller (even the AppDelegate might work). Then this controller can compare the date to the previous one ( you have to store it) and if the time difference overcomes your threshold you can fire your action by messaging the proper object. Here is a guide from Apple on how to catch the touches (you will need to overrid the touchesBegan:WithEvent: method to get the first touch)

rano