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
相关推荐
水银嘻嘻6 小时前
12 web 自动化之基于关键字+数据驱动-反射自动化框架搭建
运维·前端·自动化
厦门辰迈智慧科技有限公司15 小时前
城市综合管廊监测与维护一体化解决方案
物联网·自动化·监测
sy_cora19 小时前
IEEE 列表会议第五届机器人、自动化与智能控制国际会议
运维·人工智能·机器人·自动化
云手机管家1 天前
CDN加速对云手机延迟的影响
运维·服务器·网络·容器·智能手机·矩阵·自动化
云手机管家1 天前
账号风控突破:云手机设备指纹篡改检测与反制技术解析
android·运维·网络协议·网络安全·智能手机·矩阵·自动化
若水无华1 天前
fiddler 配置ios手机代理调试
ios·智能手机·fiddler
Aress"1 天前
【ios越狱包安装失败?uniapp导出ipa文件如何安装到苹果手机】苹果IOS直接安装IPA文件
ios·uni-app·ipa安装
struggle20251 天前
AgenticSeek开源的完全本地的 Manus AI。无需 API,享受一个自主代理,它可以思考、浏览 Web 和编码,只需支付电费。
人工智能·开源·自动化
北漂老男孩1 天前
ChromeDriver 技术生态与应用场景深度解析
java·爬虫·python·自动化
逸雨清风2 天前
Chrome更新到136以后selenium等自动化浏览器失效
selenium·自动化