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
相关推荐
LabVIEW开发9 小时前
LabVIEW是否适合商业化软件开发
自动化·labview
初学者_xuan10 小时前
零基础新手小白快速了解掌握服务集群与自动化运维(十六)集群部署模块——LVS-DR&TUN模式配置
运维·自动化·lvs
开开心心loky12 小时前
[iOS] GCD - 线程与队列
macos·ios·objective-c·cocoa
00后程序员张14 小时前
iOS 上架费用全解析 开发者账号、App 审核、工具使用与开心上架(Appuploader)免 Mac 成本优化指南
android·macos·ios·小程序·uni-app·cocoa·iphone
nanixiaowai19 小时前
Jmeter+ant+Jenkins 接口自动化框架-利用ant工具批量跑指定目录下的Jmeter 脚本
jmeter·自动化·jenkins
fukai772219 小时前
OmniFocus:专为 macOS 与 iOS 打造的专业级任务管理利器
macos·ios
VXHAruanjian88820 小时前
影刀RPA一键分析用户行为!AI智能画像,转化率提升300%[特殊字符]
自动化·rpa·微信小店·视频号·rpa9998·自动化电商·ai7982020
行走的陀螺仪20 小时前
Flutter 开发环境配置教程
android·前端·flutter·ios