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
相关推荐
云登指纹浏览器1 小时前
WebDriver反检测技术详解:如何让自动化脚本看起来像真实浏览器
运维·自动化·跨境电商
Teacher.chenchong2 小时前
AI-Agent2.0 科研全链路实战营:LLM+NotebookLM + 自动化编程 + 文献管理 + 论文写作,搭建本地科研智能体
人工智能·自动化
Maydaycxc3 小时前
Codex 配置到落地:从 API 接入到自动化RPA工作流实战
自动化·ai编程·rpa
不大姐姐AI智能体3 小时前
实测教程:用 Codex 配合 HyperFrames,把公众号文章做成可渲染的讲解型视频
人工智能·经验分享·gpt·自动化·aigc
2601_956414144 小时前
迈向智慧实验室:金现代的全链路质量管控与自动化解决方案
运维·自动化
ShGamu6 小时前
自动化输送设备公司选型参考与核心维度梳理
运维·自动化·自动化输送设备
一晌小贪欢6 小时前
第26节:自动化办公——利用 Python 自动生成动态分析报告 (PPT/PDF)
开发语言·python·数据分析·自动化·powerpoint·pandas·数据可视化
Digitally6 小时前
如何高效地将文件从电脑传输到 iPad:6 种简单方法
ios·电脑·ipad
Black蜡笔小新7 小时前
自动化AI算法训练服务器DLTM一体化训推平台构建企业专属AI能力中台
人工智能·算法·自动化