zoukankan      html  css  js  c++  java
  • iOS-阅读器常年崩溃问题记录

    在APP上线以来友盟上一直检测到一个崩溃,但是无法找到准确的复现路径

    友盟上的错误摘要

    The number of view controllers provided (3) doesn't match the number required (1) for the requested transition (null)
    The number of view controllers provided (0) doesn't match the number required (2) for the requested transition
    (null)

    完全看不出什么,网上找到各种解决方法都没有什么用,没有找到准确的错误复现路径。

    后来查资料才知道这是pageview这个系统控件的坑,这个玩意有时候在翻页的时候会自己主动翻两页,而且是不在回调里面的,而且里面的缓存机制也很混乱。

    所以,修改系统方法呗,在阅读器的基础控制器里面加上

    #pragma mark - UIPageViewController Fix
    @implementation UIPageViewController (fix)
    + (void)hyFix {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            Method dstMet = class_getInstanceMethod([UIPageViewController class], NSSelectorFromString(@"_setViewControllers:withCurlOfType:fromLocation:direction:animated:notifyDelegate:completion:"));
            Method srcMet = class_getInstanceMethod(self, @selector(hyFix_setViewControllers:withCurlOfType:fromLocation:direction:animated:notifyDelegate:completion:));
            method_exchangeImplementations(dstMet, srcMet);
        });
    }
    
    - (void)hyFix_setViewControllers:(nullable NSArray<UIViewController *> *)viewControllers
                      withCurlOfType:(UIPageViewControllerTransitionStyle)type
                        fromLocation:(CGPoint)location
                           direction:(UIPageViewControllerNavigationDirection)direction
                            animated:(BOOL)animated
                      notifyDelegate:(BOOL)notifyDelegate
                          completion:(void (^ __nullable)(BOOL finished))completion {
        if (!viewControllers.count) return;
        
        [self hyFix_setViewControllers:viewControllers withCurlOfType:type fromLocation:location direction:direction animated:animated notifyDelegate:notifyDelegate completion:completion];
    }
    
    @end

    调用

    + (void)initialize {
        [UIPageViewController hyFix];
    }

    完美!!

    检测后新版本再也没有这个崩溃了。

  • 相关阅读:
    Redis常见数据类型二:Hash
    Redis常见数据类型一:String
    了解Docker
    微信小程序倒计时秒杀
    笛卡尔积求二维数组所有组合
    git好网站网址搜集
    npm i 报错Can't find Python executable "python2.7", you can set the PYTHON env variable
    css_注意小事项总结_随时更新
    echarts使用时报错cannot read property 'querycomponents' of undefined解决方案
    echarts中获取各个省份地图的链接
  • 原文地址:https://www.cnblogs.com/qiyiyifan/p/12955352.html
Copyright © 2011-2022 走看看