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

 

 

 

完美!!

檢測后新版本再也沒有這個崩潰了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM