Skip to content

Instantly share code, notes, and snippets.

@dfox
Created August 7, 2012 18:42

Revisions

  1. David Fox revised this gist Aug 8, 2012. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions uiapplication-method-swizzling.m
    Original file line number Diff line number Diff line change
    @@ -15,9 +15,7 @@ +(void) load
    -(void) interceptAndSendEvent: (UIEvent *) event
    {
    for (UITouch *touch in event.allTouches){
    if ([touch.view isKindOfClass:[UIResponder class]]
    && touch.phase == UITouchPhaseBegan){

    if (touch.phase == UITouchPhaseBegan){
    [EventLogger logEvent:EVENT_LOGGER_TOUCHED forObject:touch.view];
    }
    }
  2. David Fox revised this gist Aug 8, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion uiapplication-method-swizzling.m
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ +(void) load
    -(void) interceptAndSendEvent: (UIEvent *) event
    {
    for (UITouch *touch in event.allTouches){
    if ([touch.view isKindOfClass:[UIView class]]
    if ([touch.view isKindOfClass:[UIResponder class]]
    && touch.phase == UITouchPhaseBegan){

    [EventLogger logEvent:EVENT_LOGGER_TOUCHED forObject:touch.view];
  3. David Fox created this gist Aug 7, 2012.
    25 changes: 25 additions & 0 deletions uiapplication-method-swizzling.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #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.view isKindOfClass:[UIView class]]
    && touch.phase == UITouchPhaseBegan){

    [EventLogger logEvent:EVENT_LOGGER_TOUCHED forObject:touch.view];
    }
    }
    [self interceptAndSendEvent:event];
    }