iOSUITableVIewCell 自动化点击埋点

iOS 中,经常要实现UITableVIewCell 点击埋点,这里通过自动化埋点的方式进行实现。

思路:通过运行时hook tableViewCell的 setSelected:animated:方法,

在交换的方法中实现埋点逻辑,并调用原来的实现

cell分类

复制代码
@property (nonatomic, strong) NSString *actionName;

- (void)setMonitorSelected:(BOOL)selected;

#import <objc/runtime.h>


static const void *monitorCellActionNameKey = "monitorCellActionNameKey";

@implementation UITableViewCell (AT)
@dynamic actionName;

+ (void)load
{
    instanceMethod_fastExchangeImplementations([self class], @selector(setSelected:animated:), [self class], @selector(setSelectedWithFilter:animated:));
}

-(void)setSelectedWithFilter:(BOOL)selected animated:(BOOL)animated
{
    if (selected && !self.skipTrack) {
        UIView *tempSuperView = self.superview;
        while (tempSuperView) {
            if ([tempSuperView isKindOfClass:[UITableView class]]) {
                break;
            }
            tempSuperView = tempSuperView.superview;
        }
        // 非LBScrllView的cell,才由setSelected触发点击采集,LB cell由didSelected触发,
        if (tempSuperView && [tempSuperView isKindOfClass:[UITableView class]] 
            && ![tempSuperView isKindOfClass:[LBTableView class]] && ![tempSuperView isKindOfClass:[LBScrollView class]]) {
            UITableView *tableView = (UITableView *)tempSuperView;
            if (![tableView isDragging] && ![tableView isTracking] && ![tableView isDecelerating]) {
                [self setMonitorSelected:selected animated:animated];
            }
        }
    }
    [self setSelectedWithFilter:selected animated:animated];
}


- (void)setMonitorSelected:(BOOL)selected
{
    [self setMonitorSelected:selected animated:NO];
}

-(void)setMonitorSelected:(BOOL)selected animated:(BOOL)animated
{
    if (selected && !self.skipTrack) {
       //埋点操作 
  
    }
}

- (NSString *)actionName {
    return objc_getAssociatedObject(self, monitorCellActionNameKey);
}

- (void)setActionName:(NSString *)monitorActionName{
    objc_setAssociatedObject(self, monitorCellActionNameKey,
                             monitorActionName,
                             OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end
相关推荐
I烟雨云渊T5 分钟前
iOS 门店营收表格功能的实现
ios
itme2684 小时前
解决cocos 2dx/creator2.4在ios18下openURL无法调用的问题
macos·objective-c·cocoa
明月看潮生6 小时前
青少年编程与数学 01-011 系统软件简介 07 iOS操作系统
ios·青少年编程·操作系统·系统软件
90后的晨仔8 小时前
RxSwift 框架解析
前端·ios
半导体守望者8 小时前
ADVANTEST R3764 66 R3765 67爱德万测试networki connection programming网络程序设计手册
经验分享·笔记·功能测试·自动化·制造
qq_279456159 小时前
CADisplayLink、NSTimer、GCD定时器
macos·objective-c·cocoa
东方佑12 小时前
使用 Python 自动化 Word 文档样式复制与内容生成
python·自动化·word
可爱小仙子12 小时前
ios苹果系统,js 滑动屏幕、锚定无效
前端·javascript·ios
未来猫咪花13 小时前
# Flutter状态管理对比:view_model vs Riverpod
flutter·ios·android studio
会又不会14 小时前
JMeter-SSE响应数据自动化2.0
jmeter·自动化