简单继承UIApplication实现点击事件监听以及埋点

1.创建MyApplication继承UIApplication

#import 

NS_ASSUME_NONNULL_BEGIN

@interface MyApplication : UIApplication

@end

NS_ASSUME_NONNULL_END

2.(重要)在main.m中添加我们的类

avatar

3.在MyApplication.m中实现监听点击的方法

- (BOOL)sendAction:(SEL)action to:(nullable id)target from:(nullable id)sender forEvent:(nullable UIEvent *)event{
    NSLog(@"进这里");
    [super sendAction:action to:target from:sender forEvent:event];
    return YES;
}

- (void)sendEvent:(UIEvent *)event{

    [super sendEvent:event];
}

4.在sendAction方法里判断点击事件和View,从而进行拦截与埋点记录

你可能感兴趣的:(简单继承UIApplication实现点击事件监听以及埋点)