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];
    }

    完美!!

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

  • 相关阅读:
    io系列浅谈
    git 删除分支--本地分支和远程分支
    提问须知
    PDF 补丁丁 0.6.2.3691 测试版发布
    PDF 补丁丁 0.6.2.3689 测试版发布
    .Net调用接口处理时间过长,前端访问超时解决方案
    Abp用多个DbContext
    IDEA 报错 Could not autowire. No beans of 'UserMapper' type found(无法自动装配。找不到类型为 'UserMapper' 的 bean)解决IDEA中自动装配,找不到类型的bean问题
    springboot整合springmvc拦截器
    springboot自动配置原理
  • 原文地址:https://www.cnblogs.com/qiyiyifan/p/12955352.html
Copyright © 2011-2022 走看看