Search code examples
objective-cioseventstouch

Listen to all touch events in an iOS app


Is it possible to somehow listen to, and catch, all the touch events occurring in an app?

The app I'm currently developing will be used in showrooms and information kiosks and I would therefore like to revert to the start section of the app if no touches has been received for a given couple of minutes. A sort of screensaver functionality, if you will. I'm planning to implement this by having a timer running in the background, which should be reset and restarted every time a touch event occurs somewhere in the app. But how can I listen to the touch events? Any ideas or suggestions?


Solution

  • You need a subclass of UIApplication (let's call it MyApplication).

    You modify your main.m to use it:

    
    return UIApplicationMain(argc, argv, @"MyApplication", @"MyApplicationDelegate");
    
    

    And you override the method [MyApplication sendEvent:]:

    
    - (void)sendEvent:(UIEvent*)event {
        //handle the event (you will probably just reset a timer)
    
        [super sendEvent:event];
    }