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
相关推荐
TYFHVB129 小时前
11款CRM数字化方案横评:获客-履约-复购全链路能力对决
大数据·人工智能·架构·自动化·流程图
TheNextByte114 小时前
如何在 iPad/iPhone 上删除语音邮件?
ios·iphone·ipad
TheNextByte115 小时前
如何修复iPhone短信消失问题?
ios·cocoa·iphone
工业HMI实战笔记16 小时前
包装机械HMI:快速换型与配方管理的界面解决方案
ui·性能优化·自动化·汽车·交互
二流小码农16 小时前
鸿蒙开发:独立开发者的烦恼之icon图标选择
android·ios·harmonyos
智先森zhi17 小时前
实战:将 Android 多Module应用迁移到 kmp+cmp
android·ios·kotlin
是Dream呀17 小时前
自动化打造信息影响力:用 Web Unlocker 和 n8n 打造你的自动化资讯系统
运维·前端·爬虫·自动化
emfuture18 小时前
工业机器人、自动化系统与PLC编程的协同关系
人工智能·机器人·自动化
凯子坚持 c18 小时前
亮数据MCP结合Dify:构建自动化视频数据抓取与智能分析工作流的深度实践
运维·eureka·自动化
TheNextByte119 小时前
如何在没有iTunes的情况下重启/恢复出厂设置iPhone
ios·cocoa·iphone