├── .gitignore ├── EventObject ├── EventFootprintCollectionViewInfo.h ├── EventFootprintCollectionViewInfo.m ├── EventFootprintGestureRecognizerInfo.h ├── EventFootprintGestureRecognizerInfo.m ├── EventFootprintObjectInfo.h ├── EventFootprintObjectInfo.m ├── EventFootprintProtocol.h ├── EventFootprintSenderInfo.h ├── EventFootprintSenderInfo.m ├── EventFootprintTableViewInfo.h └── EventFootprintTableViewInfo.m ├── EventTracer.h ├── EventTracer.m ├── HookEvent ├── UIApplication+EventDispatch.h ├── UIApplication+EventDispatch.m ├── UICollectionView+EventDispatch.h ├── UICollectionView+EventDispatch.m ├── UIGestureRecognizer+EventDispatch.h ├── UIGestureRecognizer+EventDispatch.m ├── UIResponder+EventDispatch.h ├── UIResponder+EventDispatch.m ├── UITableView+EventDispatch.h └── UITableView+EventDispatch.m ├── LICENSE ├── README.md └── Util ├── ObjcRuntimeHelper.h ├── ObjcRuntimeHelper.m ├── Swizzler.h └── Swizzler.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /EventObject/EventFootprintCollectionViewInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintCollectionViewInfo.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface EventFootprintCollectionViewInfo : NSObject 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /EventObject/EventFootprintCollectionViewInfo.m: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintCollectionViewInfo.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import "EventFootprintCollectionViewInfo.h" 10 | 11 | @implementation EventFootprintCollectionViewInfo 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /EventObject/EventFootprintGestureRecognizerInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintGestureRecognizerInfo.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/9/15. 6 | // 7 | // 8 | 9 | #import 10 | #import "EventFootprintProtocol.h" 11 | 12 | 13 | @interface EventFootprintGestureRecognizerInfo : NSObject 14 | - (instancetype)initWithGesture:(UIGestureRecognizer *)gesture; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /EventObject/EventFootprintGestureRecognizerInfo.m: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintGestureRecognizerInfo.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/9/15. 6 | // 7 | // 8 | 9 | #import "EventFootprintGestureRecognizerInfo.h" 10 | @interface GestureInfo : NSObject 11 | @property (copy,nonatomic) NSString *targetName; 12 | @property (copy,nonatomic) NSString *actionName; 13 | @property (copy,nonatomic) NSString *accessbiltyName; 14 | @property (assign,nonatomic) uint64_t addr; 15 | @end 16 | 17 | @implementation GestureInfo 18 | 19 | -(void)dealloc 20 | { 21 | [_targetName release]; 22 | [_actionName release]; 23 | [_accessbiltyName release]; 24 | [super dealloc]; 25 | } 26 | 27 | @end 28 | 29 | @interface EventFootprintGestureRecognizerInfo () 30 | @property (retain,nonatomic) GestureInfo *gestureInfo; 31 | @end 32 | 33 | @implementation EventFootprintGestureRecognizerInfo 34 | 35 | - (instancetype)initWithGesture:(UIGestureRecognizer *)gesture 36 | { 37 | self = [super init]; 38 | if (self) { 39 | self.gestureInfo = [self getTargetNameFromGesture:gesture]; 40 | 41 | } 42 | return self; 43 | } 44 | 45 | - (void)dealloc 46 | { 47 | [_gestureInfo release]; 48 | [super dealloc]; 49 | } 50 | 51 | - (GestureInfo *)getTargetNameFromGesture:(UIGestureRecognizer *)gesture 52 | { 53 | GestureInfo *gestureInfo = [[[GestureInfo alloc]init] autorelease]; 54 | Ivar targetsIvar = class_getInstanceVariable([UIGestureRecognizer class], "_targets"); 55 | id targetActionPairs = object_getIvar(gesture, targetsIvar); 56 | 57 | Class targetActionPairClass = NSClassFromString(@"UIGestureRecognizerTarget"); 58 | Ivar targetIvar = class_getInstanceVariable(targetActionPairClass, "_target"); 59 | Ivar actionIvar = class_getInstanceVariable(targetActionPairClass, "_action"); 60 | 61 | for (id targetActionPair in targetActionPairs) 62 | { 63 | id target = object_getIvar(targetActionPair, targetIvar); 64 | SEL action = (__bridge void *)object_getIvar(targetActionPair, actionIvar); 65 | gestureInfo.targetName = NSStringFromClass([target class]); 66 | gestureInfo.actionName = NSStringFromSelector(action); 67 | gestureInfo.accessbiltyName = [target valueForKey:@"accessibilityLabel"]; 68 | gestureInfo.addr = (uint64_t)target; 69 | break; 70 | } 71 | return gestureInfo; 72 | } 73 | 74 | #pragma mark - EventFootprintProtocol 75 | - (NSString *)objectName 76 | { 77 | NSString *objectName = nil; 78 | if (self.gestureInfo.accessbiltyName.length) 79 | { 80 | objectName = [NSString stringWithFormat:@"%@(%@)",self.gestureInfo.accessbiltyName,self.gestureInfo.targetName]; 81 | }else 82 | { 83 | objectName = self.gestureInfo.targetName; 84 | } 85 | return [NSString stringWithFormat:@"%@ perform selector:%@",objectName,self.gestureInfo.actionName]; 86 | } 87 | 88 | - (uint64_t)objectAddress 89 | { 90 | return self.gestureInfo.addr; 91 | } 92 | @end 93 | -------------------------------------------------------------------------------- /EventObject/EventFootprintObjectInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintObjectInfo.h 3 | // Bugtags 4 | // 5 | // Created by vedon on 9/26/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EventFootprintProtocol.h" 11 | 12 | @interface EventFootprintObjectInfo : NSObject 13 | @property (copy,nonatomic,readonly) NSString *controllerName; 14 | @property (assign,nonatomic,readonly) uint64_t controllerAddr; 15 | @property (copy,nonatomic,readonly) NSString *controllerAccessibilityName; 16 | 17 | 18 | - (instancetype)initWithController:(UIViewController *)controller; 19 | @end 20 | -------------------------------------------------------------------------------- /EventObject/EventFootprintObjectInfo.m: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintObjectInfo.m 3 | // Bugtags 4 | // 5 | // Created by vedon on 9/26/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import "EventFootprintObjectInfo.h" 10 | 11 | @implementation EventFootprintObjectInfo 12 | 13 | - (instancetype)init 14 | { 15 | self = [super init]; 16 | if (self) { 17 | _controllerName = nil; 18 | _controllerAddr = 0; 19 | _controllerAccessibilityName = nil; 20 | } 21 | return self; 22 | } 23 | 24 | - (instancetype)initWithController:(UIViewController *)controller 25 | { 26 | self = [super init]; 27 | if (self) { 28 | 29 | NSString *controllName = NSStringFromClass([controller class]); 30 | uint64_t controllerAddr = (uint64_t)(controller); 31 | 32 | _controllerName = [controllName retain]; 33 | _controllerAddr = controllerAddr; 34 | _controllerAccessibilityName = controller.accessibilityLabel; 35 | } 36 | return self; 37 | } 38 | 39 | - (void)dealloc 40 | { 41 | [_controllerName release]; 42 | [_controllerAccessibilityName release]; 43 | 44 | [super dealloc]; 45 | } 46 | 47 | #pragma mark - EventFootprintProtocol 48 | - (NSString *)objectName 49 | { 50 | return [NSString stringWithFormat:@"%@(%@)",self.controllerAccessibilityName,self.controllerName]; 51 | } 52 | 53 | - (uint64_t)objectAddress 54 | { 55 | return self.controllerAddr; 56 | } 57 | @end 58 | -------------------------------------------------------------------------------- /EventObject/EventFootprintProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintProtocol.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 9/28/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #ifndef EventFootprintProtocol_h 10 | #define EventFootprintProtocol_h 11 | #import 12 | @protocol EventFootprintProtocol 13 | @required 14 | - (NSString *)objectName; 15 | - (uint64_t)objectAddress; 16 | @end 17 | 18 | #endif /* EventFootprintProtocol_h */ 19 | -------------------------------------------------------------------------------- /EventObject/EventFootprintSenderInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintSenderInfo.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 9/28/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EventFootprintProtocol.h" 11 | 12 | @interface EventFootprintSenderInfo : NSObject 13 | @property (assign,nonatomic,readonly) uint64_t receiverAddr; 14 | @property (assign,nonatomic,readonly) uint64_t senderAddr; 15 | @property (copy,nonatomic,readonly) NSString *selector; 16 | 17 | @property (copy,nonatomic,readonly) NSString *senderName; 18 | @property (copy,nonatomic,readonly) NSString *receiverName; 19 | @property (retain,nonatomic,readonly) UIEvent *event; 20 | 21 | 22 | - (instancetype)initWithSender:(id)sender receiver:(id)receiver action:(SEL)selector event:(UIEvent *)event; 23 | @end 24 | -------------------------------------------------------------------------------- /EventObject/EventFootprintSenderInfo.m: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintSenderInfo.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 9/28/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import "EventFootprintSenderInfo.h" 10 | @interface EventFootprintSenderInfo() 11 | @property (assign,nonatomic) uint64_t receiverAddr; 12 | @property (assign,nonatomic) uint64_t senderAddr; 13 | @property (copy,nonatomic) NSString *selector; 14 | @property (copy,nonatomic) NSString *senderName; 15 | @property (copy,nonatomic) NSString *receiverName; 16 | 17 | 18 | @property (retain,nonatomic) id sender; 19 | @property (retain,nonatomic) id receiver; 20 | @property (retain,nonatomic) UIEvent *event; 21 | @end 22 | @implementation EventFootprintSenderInfo 23 | 24 | - (instancetype)initWithSender:(id)sender receiver:(id)receiver action:(SEL)selector event:(UIEvent *)event 25 | { 26 | self = [super init]; 27 | if (self) { 28 | self.sender = sender; 29 | self.receiver = receiver; 30 | self.event = event; 31 | 32 | uint64_t receiverAddr = (uint64_t)receiver; 33 | uint64_t senderAddr = (uint64_t)sender; 34 | 35 | self.receiverAddr = receiverAddr; 36 | self.senderAddr = senderAddr; 37 | self.selector = NSStringFromSelector(selector); 38 | self.senderName = NSStringFromClass([sender class]); 39 | self.receiverName = NSStringFromClass([receiver class]); 40 | 41 | } 42 | return self; 43 | } 44 | 45 | 46 | - (void)dealloc 47 | { 48 | [_senderName release]; 49 | _senderName = nil; 50 | 51 | [_receiverName release]; 52 | _receiverName = nil; 53 | 54 | [_event release]; 55 | _event = nil; 56 | 57 | [_sender release]; 58 | _sender = nil; 59 | 60 | [_receiver release]; 61 | _receiver = nil; 62 | 63 | [_selector release]; 64 | _selector = nil; 65 | 66 | [super dealloc]; 67 | } 68 | 69 | 70 | #pragma mark - EventFootprintProtocol 71 | - (NSString *)objectName 72 | { 73 | NSString *senderDes = nil; 74 | if ([self.sender isKindOfClass:[UIButton class]]) { 75 | UIButton *tempButton = self.sender; 76 | if (tempButton.titleLabel.text.length) { 77 | senderDes = [NSString stringWithFormat:@"(%@)",tempButton.titleLabel.text]; 78 | }else if(tempButton.accessibilityLabel.length) 79 | { 80 | senderDes = [NSString stringWithFormat:@"(%@)",tempButton.accessibilityLabel]; 81 | }else 82 | { 83 | senderDes = @""; 84 | } 85 | } 86 | return [NSString stringWithFormat:@"%@'s %@%@ perform %@ selector",self.receiverName,self.senderName,senderDes,self.selector]; 87 | } 88 | 89 | - (uint64_t)objectAddress 90 | { 91 | return self.senderAddr; 92 | } 93 | 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /EventObject/EventFootprintTableViewInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintTableViewInfo.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import 10 | #import "EventFootprintProtocol.h" 11 | 12 | @interface EventFootprintTableViewInfo : NSObject 13 | @property (copy,nonatomic,readonly) NSString *tableName; 14 | @property (copy,nonatomic,readonly) NSString *tableAccessbilityName; 15 | @property (assign,nonatomic,readonly) uint64_t addr; 16 | @property (retain,nonatomic,readonly) NSIndexPath *selectedIndexPath; 17 | 18 | - (instancetype)initWithTableView:(UITableView *)table selectedIndexPath:(NSIndexPath *)selectedIndexPath; 19 | @end 20 | -------------------------------------------------------------------------------- /EventObject/EventFootprintTableViewInfo.m: -------------------------------------------------------------------------------- 1 | // 2 | // EventFootprintTableViewInfo.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import "EventFootprintTableViewInfo.h" 10 | @interface EventFootprintTableViewInfo() 11 | @property (copy,nonatomic) NSString *tableName; 12 | @property (copy,nonatomic) NSString *tableAccessbilityName; 13 | @property (assign,nonatomic) uint64_t addr; 14 | @property (retain,nonatomic) NSIndexPath *selectedIndexPath; 15 | @end 16 | @implementation EventFootprintTableViewInfo 17 | 18 | - (instancetype)initWithTableView:(UITableView *)table selectedIndexPath:(NSIndexPath *)selectedIndexPath 19 | { 20 | self = [super init]; 21 | if (self) { 22 | _addr = (uint64_t)table; 23 | self.tableName = NSStringFromClass([table class]); 24 | self.tableAccessbilityName = table.accessibilityLabel; 25 | self.selectedIndexPath = selectedIndexPath; 26 | } 27 | return self; 28 | } 29 | 30 | 31 | - (void)dealloc 32 | { 33 | [_selectedIndexPath release]; 34 | [_tableName release]; 35 | [_tableAccessbilityName release]; 36 | [super dealloc]; 37 | } 38 | 39 | #pragma mark - EventFootprintProtocol 40 | - (NSString *)objectName 41 | { 42 | NSString *objectName = nil; 43 | if ([self.tableAccessbilityName length]) 44 | { 45 | objectName = [NSString stringWithFormat:@"%@(%@)",self.tableAccessbilityName,self.tableName]; 46 | }else 47 | { 48 | objectName = self.tableName; 49 | } 50 | return [NSString stringWithFormat:@"选中%@ 的 %@",objectName,self.selectedIndexPath]; 51 | } 52 | 53 | - (uint64_t)objectAddress 54 | { 55 | return self.addr; 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /EventTracer.h: -------------------------------------------------------------------------------- 1 | // 2 | // EventTracer.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 9/26/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface EventTracer : NSObject 12 | 13 | + (instancetype)shareLogger; 14 | 15 | - (void)addFootprintWithSendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event; 16 | 17 | - (void)addFootprintWithTableView:(UITableView *)table selectedIndexPath:(NSIndexPath *)indexPath; 18 | 19 | - (void)addFootprintWithGesture:(UIGestureRecognizer *)gesture; 20 | @end 21 | -------------------------------------------------------------------------------- /EventTracer.m: -------------------------------------------------------------------------------- 1 | // 2 | // EventTracer.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 9/26/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | 10 | #import "EventTracer.h" 11 | #import "EventFootprintSenderInfo.h" 12 | #import "EventFootprintGestureRecognizerInfo.h" 13 | #import "EventFootprintProtocol.h" 14 | #import "EventFootprintTableViewInfo.h" 15 | 16 | #define CacheViewHierarchy 1 17 | #define MaxRecordItem 15 18 | 19 | @interface EventTracer() 20 | @property (copy,nonatomic) NSString *filePath; 21 | @property (retain,nonatomic) NSMutableArray *footprintVC; 22 | @property (retain,nonatomic) NSArray *currentViewsInfo; 23 | @property (assign,nonatomic) NSUInteger currentGroupIndex; 24 | @end 25 | @implementation EventTracer 26 | 27 | + (instancetype)shareLogger 28 | { 29 | static EventTracer *logger = nil; 30 | static dispatch_once_t onceToken; 31 | dispatch_once(&onceToken, ^{ 32 | logger = [[EventTracer alloc]init]; 33 | }); 34 | return logger; 35 | } 36 | 37 | - (instancetype)init 38 | { 39 | self = [super init]; 40 | if (self) { 41 | self.footprintVC = [NSMutableArray array]; 42 | self.currentViewsInfo = [NSArray array]; 43 | self.currentGroupIndex = 0; 44 | } 45 | return self; 46 | } 47 | 48 | - (void)dealloc 49 | { 50 | [_filePath release]; 51 | _filePath = nil; 52 | 53 | [_footprintVC release]; 54 | _footprintVC = nil; 55 | 56 | [_currentViewsInfo release]; 57 | _currentViewsInfo = nil; 58 | 59 | [super dealloc]; 60 | } 61 | 62 | #pragma mark - Public 63 | 64 | - (void)addFootprintWithSendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event 65 | { 66 | EventFootprintSenderInfo *senderInfo = [[[EventFootprintSenderInfo alloc]initWithSender:sender receiver:target action:action event:event] autorelease]; 67 | assert(senderInfo); 68 | if (senderInfo) 69 | { 70 | [self.footprintVC addObject:senderInfo]; 71 | } 72 | [self logFootprint]; 73 | } 74 | 75 | - (void)addFootprintWithTableView:(UITableView *)table selectedIndexPath:(NSIndexPath *)indexPath 76 | { 77 | EventFootprintTableViewInfo *tableInfo = [[EventFootprintTableViewInfo alloc]initWithTableView:table selectedIndexPath:indexPath]; 78 | [self.footprintVC addObject:tableInfo]; 79 | [self logFootprint]; 80 | } 81 | 82 | - (void)addFootprintWithGesture:(UIGestureRecognizer *)gesture 83 | { 84 | EventFootprintGestureRecognizerInfo *gestureInfo = [[[EventFootprintGestureRecognizerInfo alloc]initWithGesture:gesture]autorelease]; 85 | [self.footprintVC addObject:gestureInfo]; 86 | [self logFootprint]; 87 | } 88 | 89 | 90 | #pragma mark - Utili 91 | 92 | - (void)removeActionRecordWithController:(id)object 93 | { 94 | 95 | NSInteger removeStartIndex = -1; 96 | for (int i =0; i< self.footprintVC.count ;i++) 97 | { 98 | id senderInfo = [self.footprintVC objectAtIndex:i]; 99 | if ([senderInfo isKindOfClass:[EventFootprintSenderInfo class]]) 100 | { 101 | removeStartIndex = i; 102 | }else 103 | { 104 | removeStartIndex = -1; 105 | } 106 | } 107 | if (removeStartIndex != -1) 108 | { 109 | [self.footprintVC removeObjectsInRange:NSMakeRange(removeStartIndex, self.footprintVC.count - removeStartIndex)]; 110 | } 111 | } 112 | 113 | - (void)logFootprint 114 | { 115 | if (self.footprintVC.count > MaxRecordItem + 1) 116 | { 117 | NSRange range = NSMakeRange(MaxRecordItem, self.footprintVC.count - MaxRecordItem); 118 | self.footprintVC = [NSMutableArray arrayWithArray:[self.footprintVC subarrayWithRange:range]]; 119 | } 120 | 121 | printf("\n\n\n"); 122 | NSLog(@"*********************************"); 123 | for (id object in self.footprintVC) 124 | { 125 | NSLog(@"%@",[object objectName]); 126 | } 127 | NSLog(@"*********************************"); 128 | } 129 | 130 | #pragma mark - Getter && Setter 131 | - (NSString *)filePath 132 | { 133 | if (!_filePath) { 134 | 135 | } 136 | return _filePath; 137 | } 138 | 139 | @end 140 | -------------------------------------------------------------------------------- /HookEvent/UIApplication+EventDispatch.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIApplication+EventDispatch.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 9/26/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIApplication (EventDispatch) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /HookEvent/UIApplication+EventDispatch.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIApplication+EventDispatch.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 9/26/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import "UIApplication+EventDispatch.h" 10 | #import "Swizzler.h" 11 | #import "EventTracer.h" 12 | 13 | @implementation UIApplication (EventDispatch) 14 | 15 | + (void)load 16 | { 17 | static dispatch_once_t onceToken; 18 | dispatch_once(&onceToken, ^{ 19 | SEL originalSelector = @selector(sendAction:to:from:forEvent:); 20 | SEL swizzledSelector = @selector(eventDispatchSendAction:to:from:forEvent:); 21 | [Swizzler hookSelector:originalSelector toSelector:swizzledSelector withClass:[self class]]; 22 | 23 | 24 | originalSelector = @selector(sendEvent:); 25 | swizzledSelector = @selector(eventDispatchSendEvent:); 26 | [Swizzler hookSelector:originalSelector toSelector:swizzledSelector withClass:[self class]]; 27 | 28 | 29 | 30 | originalSelector = @selector(_clearTouchesForView:); 31 | swizzledSelector = @selector(eventDispatch_clearTouchesForView:); 32 | [Swizzler hookSelector:originalSelector toSelector:swizzledSelector withClass:[self class]]; 33 | 34 | }); 35 | } 36 | 37 | 38 | 39 | - (void)eventDispatchSendAction:(SEL)action to:(nullable id)target from:(nullable id)sender forEvent:(nullable UIEvent *)event 40 | { 41 | [self eventDispatchSendAction:action to:target from:sender forEvent:event]; 42 | [[EventTracer shareLogger] addFootprintWithSendAction:action to:target from:sender forEvent:event]; 43 | } 44 | 45 | - (void)eventDispatchSendEvent:(UIEvent *)event 46 | { 47 | [self eventDispatchSendEvent:event]; 48 | 49 | } 50 | 51 | - (void)eventDispatch_clearTouchesForView:(UIView *)view 52 | { 53 | [self eventDispatch_clearTouchesForView:view]; 54 | } 55 | 56 | - (void)log:(id)something 57 | { 58 | NSLog(@"%@",something); 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /HookEvent/UICollectionView+EventDispatch.h: -------------------------------------------------------------------------------- 1 | // 2 | // UICollectionView+EventDispatch.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface UICollectionView (EventDispatch) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /HookEvent/UICollectionView+EventDispatch.m: -------------------------------------------------------------------------------- 1 | // 2 | // UICollectionView+EventDispatch.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import "UICollectionView+EventDispatch.h" 10 | #import "Swizzler.h" 11 | #import "EventTracer.h" 12 | 13 | @implementation UICollectionView (EventDispatch) 14 | + (void)load 15 | { 16 | static dispatch_once_t onceToken; 17 | dispatch_once(&onceToken, ^{ 18 | SEL originalSelector = @selector(_selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:); 19 | SEL swizzledSelector = @selector(eventDispatch_selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:); 20 | [Swizzler hookSelector:originalSelector toSelector:swizzledSelector withClass:[self class]]; 21 | }); 22 | } 23 | 24 | - (void)eventDispatch_selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(CGPoint)position notifyDelegate:(id)delegate 25 | { 26 | [self eventDispatch_selectItemAtIndexPath:indexPath animated:animated scrollPosition:position notifyDelegate:delegate]; 27 | } 28 | @end 29 | -------------------------------------------------------------------------------- /HookEvent/UIGestureRecognizer+EventDispatch.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIGestureRecognizer+EventDispatch.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 9/30/15. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface UIGestureRecognizer (EventDispatch) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /HookEvent/UIGestureRecognizer+EventDispatch.m: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // UIGestureRecognizer+EventDispatch.m 4 | // EventTracer 5 | // 6 | // Created by vedon on 9/30/15. 7 | // 8 | // 9 | 10 | #import "UIGestureRecognizer+EventDispatch.h" 11 | #import "Swizzler.h" 12 | #import "EventTracer.h" 13 | 14 | @implementation UIGestureRecognizer (EventDispatch) 15 | + (void)load 16 | { 17 | static dispatch_once_t onceToken; 18 | dispatch_once(&onceToken, ^{ 19 | 20 | SEL originalSelector = NULL; 21 | SEL swizzledSelector = NULL; 22 | 23 | originalSelector = @selector(_updateGestureWithEvent:buttonEvent:); 24 | swizzledSelector = @selector(eventDispatchUpdateGestureWithEvent:buttonEvent:); 25 | [Swizzler hookSelector:originalSelector toSelector:swizzledSelector withClass:[self class]]; 26 | 27 | 28 | originalSelector = @selector( _resetGestureRecognizer); 29 | swizzledSelector = @selector(eventDispatchResetGestureRecognizer); 30 | [Swizzler hookSelector:originalSelector toSelector:swizzledSelector withClass:[self class]]; 31 | 32 | 33 | }); 34 | } 35 | 36 | 37 | - (void)eventDispatchUpdateGestureWithEvent:(UIEvent *)event buttonEvent:(UIEvent *)buttonEvent 38 | { 39 | [self eventDispatchUpdateGestureWithEvent:event buttonEvent:buttonEvent]; 40 | } 41 | 42 | - (BOOL)eventDispatchResetGestureRecognizer 43 | { 44 | if (self.state == UIGestureRecognizerStateEnded) 45 | { 46 | [[EventTracer shareLogger] addFootprintWithGesture:self]; 47 | } 48 | return [self eventDispatchResetGestureRecognizer]; 49 | } 50 | 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /HookEvent/UIResponder+EventDispatch.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIResponder+EventDispatch.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/16/15. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface UIResponder (EventDispatch) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /HookEvent/UIResponder+EventDispatch.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIResponder+EventDispatch.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/16/15. 6 | // 7 | // 8 | 9 | #import "UIResponder+EventDispatch.h" 10 | #import "Swizzler.h" 11 | 12 | @implementation UIResponder (EventDispatch) 13 | + (void)load 14 | { 15 | static dispatch_once_t onceToken; 16 | dispatch_once(&onceToken, ^{ 17 | 18 | SEL originalSelector = @selector(targetForAction:withSender:); 19 | SEL swizzledSelector = @selector(eventDispatchtargetForAction:withSender:); 20 | [Swizzler hookSelector:originalSelector toSelector:swizzledSelector withClass:[self class]]; 21 | 22 | }); 23 | } 24 | 25 | - (id)eventDispatchtargetForAction:(id)actino withSender:(id)sender 26 | { 27 | id target = [self eventDispatchtargetForAction:actino withSender:sender]; 28 | return target; 29 | } 30 | @end 31 | -------------------------------------------------------------------------------- /HookEvent/UITableView+EventDispatch.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+EventDispatch.h 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface UITableView (EventDispatch) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /HookEvent/UITableView+EventDispatch.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+EventDispatch.m 3 | // EventTracer 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import "UITableView+EventDispatch.h" 10 | #import "Swizzler.h" 11 | #import "EventTracer.h" 12 | 13 | @implementation UITableView (EventDispatch) 14 | 15 | + (void)load 16 | { 17 | static dispatch_once_t onceToken; 18 | dispatch_once(&onceToken, ^{ 19 | SEL originalSelector = @selector(_selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:); 20 | SEL swizzledSelector = @selector(eventDispatch_selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:); 21 | [Swizzler hookSelector:originalSelector toSelector:swizzledSelector withClass:[self class]]; 22 | }); 23 | } 24 | 25 | - (void)eventDispatch_selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(CGPoint)point notifyDelegate:(id)delegate 26 | { 27 | [self eventDispatch_selectRowAtIndexPath:indexPath animated:animated scrollPosition:point notifyDelegate:delegate]; 28 | [[EventTracer shareLogger]addFootprintWithTableView:self selectedIndexPath:indexPath]; 29 | } 30 | @end 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 vedon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EventTracer 2 | 3 | 1)记录用户交互的事件 4 | 5 | 2)打印出当前按钮,手势等执行的方法 6 | 7 | 主要用于调试,可以快速定位一些按钮事件实现的地方,例如:不需要用reveal 定位button ,再定位到button 的方法。 8 | 直接把文件拖到项目就可以使用,暂时不支持ARC。 9 | 10 | 11 | -------------------------------------------------------------------------------- /Util/ObjcRuntimeHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // ObjcRuntimeHelper.h 3 | // iUCWEB 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface ObjcRuntimeHelper : NSObject 12 | 13 | + (void)getAllMethods; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Util/ObjcRuntimeHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // ObjcRuntimeHelper.m 3 | // iUCWEB 4 | // 5 | // Created by vedon on 10/19/15. 6 | // 7 | // 8 | 9 | #import "ObjcRuntimeHelper.h" 10 | 11 | @implementation ObjcRuntimeHelper 12 | 13 | + (void)getAllMethods 14 | { 15 | unsigned int methodCount; 16 | Method *methodList = class_copyMethodList(self, &methodCount); 17 | unsigned int i = 0; 18 | for (; i < methodCount; i++) { 19 | NSLog(@"%@ - %@", [NSString stringWithCString:class_getName(self) encoding:NSUTF8StringEncoding], [NSString stringWithCString:sel_getName(method_getName(methodList[i])) encoding:NSUTF8StringEncoding]); 20 | } 21 | free(methodList); 22 | 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Util/Swizzler.h: -------------------------------------------------------------------------------- 1 | // 2 | // Swizzler.h 3 | // Bugtags 4 | // 5 | // Created by vedon on 9/26/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Swizzler : NSObject 12 | + (void)hookSelector:(SEL)originalSelector toSelector:(SEL)swizzledSelector withClass:(Class)class; 13 | @end 14 | -------------------------------------------------------------------------------- /Util/Swizzler.m: -------------------------------------------------------------------------------- 1 | // 2 | // Swizzler.m 3 | // Bugtags 4 | // 5 | // Created by vedon on 9/26/15. 6 | // Copyright © 2015 bugtags.com. All rights reserved. 7 | // 8 | 9 | #import "Swizzler.h" 10 | #import 11 | 12 | @implementation Swizzler 13 | 14 | + (void)hookSelector:(SEL)originalSelector toSelector:(SEL)swizzledSelector withClass:(Class)class 15 | { 16 | Method originalMethod = class_getInstanceMethod(class, originalSelector); 17 | Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); 18 | 19 | BOOL didAddMethod = 20 | class_addMethod(class, 21 | originalSelector, 22 | method_getImplementation(swizzledMethod), 23 | method_getTypeEncoding(swizzledMethod)); 24 | 25 | if (didAddMethod) { 26 | class_replaceMethod(class, 27 | swizzledSelector, 28 | method_getImplementation(originalMethod), 29 | method_getTypeEncoding(originalMethod)); 30 | } else { 31 | method_exchangeImplementations(originalMethod, swizzledMethod); 32 | } 33 | } 34 | @end 35 | --------------------------------------------------------------------------------