UIPresentationController crash just points to AppDelegate

喜欢而已 提交于 2020-01-02 07:22:09

问题


Screenshots :


I am getting a lot of these crashes but the problem is I'm just being pointed to my appDelegate first line. I've no idea where to look for the issue. Any ideas where I could start to investigate from the following crash report?

Crashed: com.apple.main-thread
0  UIKit                          0x18d005640 __56-

[UIPresentationController runTransitionForCurrentState]_block_invoke + 460
1  UIKit                          0x18cf27aa8 _runAfterCACommitDeferredBlocks + 292
2  UIKit                          0x18cf1ae5c _cleanUpAfterCAFlushAndRunDeferredBlocks + 288
3  UIKit                          0x18ccac464 _afterCACommitHandler + 132
4  CoreFoundation                 0x1836a6cdc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
5  CoreFoundation                 0x1836a4694 __CFRunLoopDoObservers + 412
6  CoreFoundation                 0x1836a4c50 __CFRunLoopRun + 1292
7  CoreFoundation                 0x1835c4c58 CFRunLoopRunSpecific + 436
8  GraphicsServices               0x185470f84 GSEventRunModal + 100
9  UIKit                          0x18cd1d5c4 UIApplicationMain + 236
10 AppName                        0x100ae3ca4 main (AppDelegate.swift:23)
11 libdyld.dylib                  0x1830e456c start + 4

Update:

Based off the following:

App crashing on runTransitionForCurrentState but no clue as to why

I'm looking at potential causes and am wondering about the following code.

I have the following func for presenting a view with an activity indicator while I am doing a sync process.

public func displayActivityAlertWithCompletion(_ title: String, ViewController: UIViewController, completionHandler: @escaping ()->())
{
    let pending = UIAlertController(title: "\n\n\n"+title, message: nil, preferredStyle: .alert)
    //create an activity indicator
    let indicator = UIActivityIndicatorView(frame: pending.view.bounds)
    indicator.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    indicator.color = UIColor(rgba: Palette.loadingColour)
    //add the activity indicator as a subview of the alert controller's view
    pending.view.addSubview(indicator)
    indicator.isUserInteractionEnabled = false
    // required otherwise if there buttons in the UIAlertController you will not be able to press them
    indicator.startAnimating()


    ViewController.present(pending, animated: true, completion: completionHandler)
}

I then use this func like so:

displayActivityAlertWithCompletion("Pushing Data", ViewController: self){_ in
    Helper_class.doSync(_cleanSync: false){
        //sync is complete
        Prefs.is_Syncing = false
        DispatchQueue.main.async {
            //dismiss my view with activity alert
            self.dismiss(animated: true){
                //dismiss my viewcontroller
                Toast(text: "Upload sync completed").show()
                self.dismiss(animated: true, completion: nil)
            }
        }
    }
}

Would this be a potential cause for the UIKit issue?


回答1:


Follow these steps, you can make it: 1. Open Navigator; 2. Switch to BreakPoint Navigator; 3. Click the "+" button in the bottom left; 4. When pop up, click "Exception BreakPoint".

Then run your project again, it will break at the exact point.




回答2:


Following are my suggestions :

  1. Try to replicate the issue yourself. Since you know which screen has the crash, you could easily identify the viewcontroller/class causing the crash. That would be a good start. Once yo have identified the class, check
    • If the crash occurs while the screen is loading or leaving the screen. Put breakpoints on UIViewController functions - viewDidLoad, viewWillAppear, viewWillDisappear and so on.
    • If crash occurs on an event like button tap, segment change or table reload.
  2. Get more information from Crashlytics report. It always comes with the file name where crash had occurred. I have attached a Crashlytics screenshot which shows list of crashes along with file name.
  3. Update your question with more information after you conduct the above.

As per the your code, you are dismissing the same viewController twice. Take pending as a global variable. And dismiss it as :

pending.dismiss(animated: true, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(0.1)) {
    self.dismiss(animated: true, completion: nil)  // This will be called after above time gap.
}



回答3:


I had an issue with a crash in the UIPresentationController constructor when doing some migration some year.

For me, the issue was solved by changing presenting to source in the UIViewControllerTransitioningDelegate.

Like:

public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
    return PresentationController(presentedViewController: presented, presenting: source)
}

Though it was reproducible all times, so perhaps not the same issue..




回答4:


I encountered the same crash. And I reproduced this crash by this case. There is a viewController was presented. The crash happens when I use this viewController to present another viewController while this viewController is being dismissed with animation. I think you can add some condition to avoid this case such as judging if the viewContoller.isBeingDismissed. If isBeingDismissed is true, use other viewControllers to do present action.



来源:https://stackoverflow.com/questions/48764872/uipresentationcontroller-crash-just-points-to-appdelegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!