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
相关推荐
志栋智能10 小时前
超自动化运维如何提升安全合规水平?
运维·安全·自动化
Urbano12 小时前
22 道工序、核心难点与自动化升级方案
运维·自动化
Urbano12 小时前
工装裤与外套缝制自动化对比:真实设备选型与工艺适配指南
运维·自动化
GlobalSign数字证书12 小时前
SSL证书过期致业务宕机?企业证书管理三大痛点与自动化方案
网络协议·自动化·ssl
wh_xia_jun12 小时前
Playwright 自动化实战指南 - 以 12306 余票查询为例
运维·自动化
极验12 小时前
智能体时代的自动化对抗:Agent Bot 与隐匿技术共舞
运维·自动化
他们都不看好你,偏偏你最不争气13 小时前
【iOS】Runtime - Part 2 && 消息发送:缓存、查找与转发
macos·ios·objective-c·cocoa
施努卡机器视觉13 小时前
SNK施努卡转子自动化生产线:从铁芯上料到下线,精密装配方案
运维·自动化
心前阳光13 小时前
Unity资源导入之自动化资源导入
unity·自动化·游戏引擎
糖果店的幽灵14 小时前
软件测试接口测试从入门到精通:Python接口自动化 - pytest测试框架
软件测试·python·功能测试·自动化·pytest·接口测试