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
相关推荐
Haha_bj28 分钟前
Swift ——详解Any、AnyObject、 AnyClass
ios·swift
Haha_bj1 小时前
Swift 中的async和await
ios·swift
你的秋裤穿反了1 小时前
二. 设置光标样式
自动化
北京耐用通信1 小时前
耐达讯自动化Profibus光纤转换器为您的水处理系统装上“光纤高速路”,数据从此畅通无阻!
网络·人工智能·科技·网络协议·自动化·信息与通信
qq_526099131 小时前
PCIe-8052 双口万兆光纤图像采集卡:万兆传输赋能,解锁工业采集新速度
网络·计算机视觉·自动化
Hotlogin3 小时前
RPA 在跨境业务中的工程实践:从流程录制到批量自动化执行
运维·自动化·rpa
科普瑞传感仪器3 小时前
从“盲插”到“智插”:六维力控制技术如何革新PCBA自动化装配?
运维·人工智能·科技·ai·机器人·自动化·无人机
2501_915106324 小时前
iOS 抓不到包怎么办?从 HTTPS 代理排查到 TCP 数据流捕获的全链路解决方案
android·tcp/ip·ios·小程序·https·uni-app·iphone
游戏开发爱好者84 小时前
APP上架苹果应用商店经验教训与注意事项
android·ios·小程序·https·uni-app·iphone·webview
张飞签名上架4 小时前
苹果TF签名:革新应用分发的解决方案
人工智能·安全·ios·苹果签名·企业签名·苹果超级签名