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
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |