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
相关推荐
人月神话-Lee7 分钟前
【图像处理】高斯模糊——最优雅的模糊算法
图像处理·人工智能·算法·ios·ai编程·swift
@大迁世界14 分钟前
iPhone 18e,可能不再“低一档”
ios·iphone
无限进步_18 分钟前
【Linux】Makefile:让编译自动化
linux·运维·自动化
User_芊芊君子23 分钟前
一条命令搞定 mysql_exporter 部署,Shell 脚本把重复配置这件事自动化了
android·mysql·自动化
qq_1969761731 分钟前
硬核教程:用Gemini境像站构建端到端自动化办公工作流,告别重复操作(国内免费镜像实测)
运维·自动化
流浪00136 分钟前
Linux篇(八) Make 与 Makefile 超详细入门教程|从零基础到手写自动化编译
linux·运维·自动化
柱子jason40 分钟前
云端IOT-Tree Server如何最低成本通过DTU对接现场西门子S7-200 Smart
物联网·自动化·plc·iot-tree·s7-200 smart
OidEncoder1 小时前
拉绳位移传感器赋能水利管控:精准测控筑牢闸门开度运行安全防线
安全·自动化·信息与通信
helx821 小时前
Gemini镜像站驱动的运维事件自动复盘:从日志聚类到根因定位的全链路自动化
运维·自动化·聚类
收放扳机1 小时前
蜘蛛机械手高速收板方案:CD视觉与并联机械手的技术特点
人工智能·科技·自动化·制造·pcb工艺