Skip to content

Instantly share code, notes, and snippets.

@matinm
Created April 28, 2014 22:46
Show Gist options
  • Select an option

  • Save matinm/11386280 to your computer and use it in GitHub Desktop.

Select an option

Save matinm/11386280 to your computer and use it in GitHub Desktop.
Automatic event-tracking for iOS analytics.
#import "UIApplication+EventAutomator.h"
#import <objc/runtime.h>
@implementation UIApplication (EventAutomator)
+ (void)load {
Class class = [self class];
SEL originalSelector = @selector(sendAction:to:from:forEvent:);
SEL replacementSelector = @selector(heap_sendAction:to:from:forEvent:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method replacementMethod = class_getInstanceMethod(class, replacementSelector);
method_exchangeImplementations(originalMethod, replacementMethod);
}
- (BOOL)heap_sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event {
NSString *selectorName = NSStringFromSelector(action);
printf("Selector %s occurred.\n", [selectorName UTF8String]);
return [self heap_sendAction:action to:target from:sender forEvent:event];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment