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
相关推荐
weixin_468466853 小时前
工业相机成像原理新手入门指南
人工智能·自动化·机器视觉·工业相机·光学·光学系统·成像原理
U盘失踪了3 小时前
claude code 用 Playwright + “webapp-testing” 技能包,编写前端自动化
自动化
weixin_468466854 小时前
MoneyPrinterTurbo 短视频自动化生产实战指南
运维·人工智能·自动化·大模型·音视频·moneyprinter
志栋智能7 小时前
小步快跑:从单一场景开启超自动化巡检之旅
运维·网络·人工智能·自动化
帅次7 小时前
Android 17 开发者实战:核心更新与应用场景落地指南
android·java·ios·android studio·iphone·android jetpack·webview
人月神话Lee8 小时前
【图像处理】Core Image 与 GPU 渲染管线——让滤镜飞起来
ios·ai编程·图像识别
Agent手记8 小时前
电信运营商如何用AI实现携号转网自动处理?基于实在Agent的业务自动化落地与TARS大模型解析方案
运维·人工智能·ai·自动化
志栋智能10 小时前
超越监控:超自动化巡检提供的主动价值
运维·网络·人工智能·自动化
搜狐技术产品小编202310 小时前
破局与重构:纯端侧 Android 自动化引擎的尝试与未来推演
android·运维·重构·自动化
志栋智能14 小时前
超自动化运维:如何降低人为错误?
大数据·运维·网络·人工智能·自动化