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
相关推荐
缺点内向6 小时前
C#编程实战:如何为Word文档添加背景色或背景图片
开发语言·c#·自动化·word·.net
hhy_smile7 小时前
Ubuntu24.04 环境配置自动脚本
linux·ubuntu·自动化·bash
小W与影刀RPA11 小时前
【影刀 RPA】 :文档敏感词批量替换,省时省力又高效
人工智能·python·低代码·自动化·rpa·影刀rpa
星夜落月11 小时前
Certimate证书自动化管理:从零开始的私有化部署指南
运维·自动化·ssl
0思必得012 小时前
[Web自动化] Selenium执行JavaScript语句
前端·javascript·爬虫·python·selenium·自动化
百***787512 小时前
Clawdbot 技术实战:基于一步 API 快速接入,打造本地化 AI 自动化助手
运维·人工智能·自动化
0思必得012 小时前
[Web自动化] Selenium截图
前端·爬虫·python·selenium·自动化
2501_9159214313 小时前
傻瓜式 HTTPS 抓包,简单抓取iOS设备数据
android·网络协议·ios·小程序·https·uni-app·iphone
Fleshy数模13 小时前
从入门到实战:用 Selenium 驱动 Edge 浏览器完成自动化操作
selenium·edge·自动化
Max_uuc13 小时前
【C++ 硬核】给单片机装上“反射”:手写极简属性系统 (Property System) 自动化 CLI 开发
运维·自动化