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
相关推荐
安科瑞-小李2 小时前
铁路智能运维进化路线:自动化→状态可视→预测维护
运维·自动化·数据采集·能耗可视化
酷可达拉斯2 小时前
自动化运维-Ansible任务控制与流程控制
运维·自动化·ansible
HiDev_2 小时前
【非标自动化】2、认识元器件(电机保护器)
运维·自动化
深念Y3 小时前
基于 NapCat 与本地 RAG 的群聊 AI 机器人方案(ARM64 部署)
人工智能·ai·机器人·node.js·自动化·情感陪伴·bot
工业HMI实战笔记3 小时前
解放双手,声控未来:抗噪语音交互如何革新嘈杂车间的HMI操作体验
人工智能·学习·自动化·制造
代码方舟4 小时前
零信任架构实战:基于天远车辆vin码查车辆信息详版构建自动化汽车金融审批网关
人工智能·架构·自动化·汽车
qq_267612894 小时前
Gitee CodePecker行业场景化落地指南:金融、车联网与IoT双引擎选型与工程化路径
前端·gitee·自动化
跨境小彭4 小时前
Temu运营优化方案:活动库存自动化管控,解决断流、超卖与权重下跌问题
大数据·运维·人工智能·自动化·跨境电商·temu·temu电商运营
AI多Agent协作实战派4 小时前
AI多Agent协作系统实战(三十九):AI修对了Bug,却越了权——自动化团队的第一条铁律
人工智能·自动化·bug
2501_941982054 小时前
私域 AI 智能体自动化系统架构
运维·人工智能·自动化