iOS UICollectionViewCell 点击事件自动化埋点

iOS 中经常要进行埋点,我们这里支持 UICollectionViewCell. 进行自动化埋点,思路:

通过hook UICollectionViewCell 的setSelected:方法,

则新的方法中执行埋点逻辑,并调用原来的方法

直接上代码

复制代码
@implementation UICollectionViewCell (LB)

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

-(void)setSelectedWithFilter:(BOOL)selected
{
    // 过滤拼音键盘提示词
    if (selected && !self.skipTrack ) {
        UIView *tempSuperView = self.superview;
        while (tempSuperView) {
            if ([tempSuperView isKindOfClass:[UICollectionView class]]) {
                break;
            }
            tempSuperView = tempSuperView.superview;
        }
        // 非LBScrllView的cell,才由setSelected触发点击采集,LB cell由didSelected触发,
        if (tempSuperView && [tempSuperView isKindOfClass:[UICollectionView class]]
            && ![tempSuperView isKindOfClass:[LBCollectionView class]] && ![tempSuperView isKindOfClass:[LBScrollView class]]) {
            UICollectionView *collectionView = (UICollectionView *)tempSuperView;
            if (![collectionView isDragging] && ![collectionView isTracking] && ![collectionView isDecelerating]) {
                [self setMonitorSelected:selected];
            }
        }
    }
    [self setSelectedWithFilter:selected];
}


- (void)setMonitorSelected:(BOOL)selected
{
    if (selected && !self.skipTrack) {
     //执行埋点逻辑
   }
}

- (void)logClickCell
{
 
}

@end
相关推荐
小趴菜克鲁里27 分钟前
游戏Excel配置自动化导出二进制工具链并生成对应配置类详解
游戏·自动化·excel
lihao lihao1 小时前
页面自动化常见函数重点说明
运维·自动化
iambooo1 小时前
基于日志的故障定位与自动化分析体系
运维·自动化
belldeep1 天前
python:如何将豆包AI中历史对话 备份到本地 backup目录下?
人工智能·python·ai·自动化·backup·豆包
软希网分享源码1 天前
AIGC自动化编程实战(Python、Java、JavaScript和VBA) -2.9G课程
python·自动化·aigc
qq_454245031 天前
开源GraphMindStudio工作流引擎:自动化与AI智能体的理想核心
运维·人工智能·开源·c#·自动化
deepdata_cn1 天前
标签质量自动化评估
自动化·标签质量
教男朋友学大模型2 天前
平衡AI自动化与人工干预
大数据·人工智能·自动化
田里的水稻2 天前
PPB_自动化及其相近期刊
运维·自动化