• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

iOS 替换navigationController 的push方法,使页面无痕获取上页面的pageCode

武飞扬头像
刘小哈哈哈
帮助1

给navigationControler 添加一个分类

@implementation UINavigationController (Track)

- (void)track_pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count < 2) {
        return;
    }
    
    UIViewController *currentVC = self.viewControllers[self.viewControllers.count - 2];
    
    //vc不存在
    if (!currentVC || !viewController) {
#if DEBUG
        NSAssert(NO, @"currentVC or pushVC not exsit");
#endif
        return;
    }
    
    //vc不支持VVSnowplowTrackParams协议
    if (![currentVC conformsToProtocol:@protocol(VVSnowplowTrackParams)] ||
        ![viewController conformsToProtocol:@protocol(VVSnowplowTrackParams)]) {
        NSLog(@"not conform VVSnowplowTrackParams protocol. Current: %@, Push: %@.", currentVC, viewController);
        return;
    }
    
    //设置来源页面
    [(id <VVSnowplowTrackParams>)viewController setSpReferrer:[(id <VVSnowplowTrackParams>)currentVC spUri]];
}

学新通

交换push 方法

  (void)vv_swizzleMethod
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [UINavigationController class];
        SEL originSelector = @selector(pushViewController:animated:);
        SEL swizzledSelector = @selector(new_pushViewController:animated:);
        [NSObject exchangeInstanceMethod:class originalSel:originSelector swizzledSel:swizzledSelector];
    });
}

- (void)new_pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [self new_pushViewController:viewController animated:animated];
    [self track_pushViewController:viewController animated:animated];
}

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhifkjbb
系列文章
更多 icon
同类精品
更多 icon
继续加载