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
相关推荐
xbd_zc42 分钟前
【Jenkins简单自动化部署案例:基于Docker和Harbor的自动化部署流程记录】
docker·自动化·jenkins·harbor
*拯3 小时前
Uniapp Android/IOS 获取手机通讯录
android·ios·uni-app
水银嘻嘻3 小时前
web 自动化之 selenium 下拉&鼠标键盘&文件上传
selenium·自动化
深圳安锐科技有限公司3 小时前
高速边坡监测成本高?自动化如何用精准数据省预算?
运维·自动化
IT轻生活4 小时前
TestNG接口自动化
运维·自动化
水银嘻嘻5 小时前
Web 自动化之 HTML & JavaScript 详解
前端·自动化·html
天天打码5 小时前
Lynx-字节跳动跨平台框架多端兼容Android, iOS, Web 原生渲染
android·前端·javascript·ios
莫负初6 小时前
Excel使用VBA批量计算指定列的中位数和标准差并筛选指定列数据
数据分析·自动化·excel·vba·方差·标准差
lilili啊啊啊7 小时前
iOS safari和android chrome开启网页调试与检查器的方法
android·ios·safari
水银嘻嘻7 小时前
web 自动化之 Unittest 应用:报告&装饰器&断言
前端·python·自动化