-
-
Save chunta/e3128a414ae183ec9b9011f73585fbf2 to your computer and use it in GitHub Desktop.
Method Swizzling in UIApplication to Capture Touch Events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIApplication+EventInterceptor.h" | |
#import <objc/runtime.h> | |
#import "EventLogger.h" | |
@implementation UIApplication (EventInterceptor) | |
+(void) load | |
{ | |
//Swap the implementations of our interceptor and the original sendEvent: | |
Method oldMethod = class_getInstanceMethod(self, @selector(sendEvent:)); | |
Method newMethod = class_getInstanceMethod(self, @selector(interceptAndSendEvent:)); | |
method_exchangeImplementations(oldMethod, newMethod); | |
} | |
-(void) interceptAndSendEvent: (UIEvent *) event | |
{ | |
for (UITouch *touch in event.allTouches){ | |
if (touch.phase == UITouchPhaseBegan){ | |
[EventLogger logEvent:EVENT_LOGGER_TOUCHED forObject:touch.view]; | |
} | |
} | |
[self interceptAndSendEvent:event]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment