CoreFoundation/ UIKit thousands crashes in iOS 15

Since iOS 15 was released. My app has suffer thousands of crashes (only in ios 15), and I don't know exactly why because I cant reproduce the error. The error is this:

Crashed: com.apple.main-thread
0  MyAppName                      0xa7464 CustomSlideMenuController.setNavBarToTheView() + 127 (CustomSlideMenuController.swift:127)
1  MyAppName                      0xa6f4c @objc CustomSlideMenuController.viewDidLayoutSubviews() + 93 (CustomSlideMenuController.swift:93)
2  UIKitCore                      0x18dea0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 3092
3  QuartzCore                     0x3f280 CA::Layer::layout_if_needed(CA::Transaction*) + 536
4  QuartzCore                     0x31aa8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 144
5  QuartzCore                     0x460b0 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 500
6  QuartzCore                     0x4f174 CA::Transaction::commit() + 680
7  QuartzCore                     0x31210 CA::Transaction::flush_as_runloop_observer(bool) + 88
8  CoreFoundation                 0x41570 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
9  CoreFoundation                 0x10854 __CFRunLoopDoObservers + 572
10 CoreFoundation                 0xb8ec __CFRunLoopRun + 1052
11 CoreFoundation                 0x1f3c8 CFRunLoopRunSpecific + 600
12 GraphicsServices               0x138c GSEventRunModal + 164
13 UIKitCore                      0x51b0bc -[UIApplication _run] + 1100
14 UIKitCore                      0x298be8 UIApplicationMain + 2124
15 MyAppName                      0x6d94 main + 27 (AppDelegate.swift:27)
16 ???                            0x101b89a24 (More)

The code is this (CustomSlideMenuController.swift)

90    override func viewDidLayoutSubviews() {
91        super.viewDidLayoutSubviews()
92        self.setNavBarToTheView()
93        self.setFooterToTheView()
94    }
95
96  func setNavBarToTheView()
97    {
98        if ( (navBar != nil) && (navBar?.subviews.contains(headerView))!) {
99            return
100        }
101        
102        AppDelegate.getAppDelegate.slideMenuController.delegate = self
103        navController = AppDelegate.getAppDelegate.mainViewController.navigationController
104        navController.delegate = self
105        
106        navBar = self.navController.navigationBar
107        navController.navigationBar.isTranslucent = false
108        
109        navController.popToRootViewController(animated: false)
110        
111        var frame: CGRect = headerView.frame
112        
113        var statusBarHeight:CGFloat = 0.0
114        if #available(iOS 13.0, *) {
115            statusBarHeight = (UIApplication.shared.keyWindow?.windowScene?.statusBarManager?.statusBarFrame.height)!
116        }else{
117            statusBarHeight = UIApplication.shared.statusBarFrame.height
118        }
119        
120        frame.origin.y = frame.origin.y  - statusBarHeight
121        frame.size.width = navBar.bounds.width
122        frame.size.height = navBar.bounds.height + statusBarHeight
123        
124        headerView.custom_setConstraintValue(frame.size.width, to: NSLayoutConstraint.Attribute.width)
125        headerView.custom_setConstraintValue(frame.size.height, to: NSLayoutConstraint.Attribute.height)
126        headerView.frame = frame
127        navBar.addSubview(headerView)
128    }

I tried to put the code inside the main thread but error persists. I use the app with an iphone, ipad, simulators... but I can't reproduce the error. All these crashes are in iOS 15. Any help? ios swift

Could you show the error message you get ?

In an older thread eskimo explained the error is due to wrong use of observer :

https://developer.apple.com/forums/thread/100012

or

https://stackoverflow.com/questions/17969493/cfrunloop-is-calling-out-to-an-observer-callback-function-18-23-corefoundati

Could be that iOS 15 is less tolerant to such error than previous iOS.

CoreFoundation/ UIKit thousands crashes in iOS 15
 
 
Q