Goal C: Is it possible to intercept all user actions in one class?

Is it possible to intercept all user actions, such as tap, swipe, enter text, etc. in all windows of my application?

+1
source share
1 answer

As I said in the comments, subclass UIApplicationand override the instance method sendEvent:.

From the documentation for the UIApplication class, method -sendEvent::

Discussion

If you need it, you can intercept incoming events by subclassing UIApplication and overriding this method. For each event you intercept, you must send it by calling [super sendEvent: event] after processing the event in your implementation.

, :

CustomUIApplication.h:

@interface CustomUIApplication:UIApplication
- (void)sendEvent:(UIEvent *)event;
@end

CustomUIApplication.m:

@implementation CustomUIApplication

- (void)sendEvent:(UIEvent *)event
{
    // ...Do your thing...

    [super sendEvent:event];
}
@end

, , UIApplication. , Objective-C, , Swift.

+3

Source: https://habr.com/ru/post/1676627/


All Articles