应用程序不以模态呈现,但因“应用程序试图以模态呈现活动控制器”而崩溃

xap*_*hod 2 ios

我已经看了好几天了,我无法弄清楚发生了什么。

我的崩溃每天影响 2% 的用户(跨 iPad 和 iPhone,不限于 iOS 12,底部的完整堆栈跟踪): Application tried to present modally an active controller <DownloadViewController: 0x10a0c3c00>.

我在我的代码UIViewController presentViewController:animated中没有任何地方调用,并且没有到DownloadViewController. 总有一个UINavigationController礼物(它是故事板的初始 VC)。

我尝试模拟竞争条件,其中 segues 执行两次,或者 a在它UIAlertControllerUIViewController下消失后仍然显示,并尝试对活动 VC 执行 segue,但我无法重现此崩溃:我最多可能导致的是DownloadViewController被推到UINavigationController两次(不是世界末日也没有崩溃)。

在我添加了一些UIAlertControllers之后,这个崩溃开始发生,所以我假设它们与它有关,但我不知道是怎么回事。

有什么想法下一步要去哪里?


Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x2201b0518 __exceptionPreprocess
1  libobjc.A.dylib                0x21f38b9f8 objc_exception_throw
2  UIKitCore                      0x24c01859c -[UIViewController _presentViewController:withAnimationController:completion:]
3  UIKitCore                      0x24c01aa7c __63-[UIViewController _presentViewController:animated:completion:]_block_invoke
4  UIKitCore                      0x24c033570 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:]
5  UIKitCore                      0x24c02f930 -[_UIViewControllerTransitionContext _runAlongsideCompletions]
6  UIKitCore                      0x24c02f608 -[_UIViewControllerTransitionContext completeTransition:]
7  UIKitCore                      0x24ca2ba00 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:]
8  UIKitCore                      0x24ca02758 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
9  UIKitCore                      0x24ca02d2c -[UIViewAnimationState animationDidStop:finished:]
10 UIKitCore                      0x24ca02dcc -[UIViewAnimationState animationDidStop:finished:]
11 QuartzCore                     0x22464f958 CA::Layer::run_animation_callbacks(void*)
12 libdispatch.dylib              0x21fbf17d4 _dispatch_client_callout
13 libdispatch.dylib              0x21fb9f004 _dispatch_main_queue_callback_4CF$VARIANT$mp
14 CoreFoundation                 0x220141ec0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
15 CoreFoundation                 0x22013cdf8 __CFRunLoopRun
16 CoreFoundation                 0x22013c354 CFRunLoopRunSpecific
17 GraphicsServices               0x22233c79c GSEventRunModal
18 UIKitCore                      0x24c5afb68 UIApplicationMain
19 WeDownload                     0x100ea1f40 main (main.m:14)
20 libdyld.dylib                  0x21fc028e0 start
Run Code Online (Sandbox Code Playgroud)

xap*_*hod 5

解决了。问题是在这样的块内:

[UIView transitionWithView:self.view duration:0.2 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{

...我[self presentViewController:alert animated:YES completion:nil];连续两次有效地调用(其中警报是一个 UIAlertController)。

最重要的学习:在错误消息中Application tried to present modally an active controller <DownloadViewController: 0x10a0c3c00>,DownloadViewController 是演示者而不是被呈现的东西。如果我正确理解了该错误消息,我会早几天弄清楚这一点。

  • 请注意,iOS 14 SDK 中的措辞已得到改进:“应用程序尝试以模态方式呈现具有父视图控制器 &lt;UINavigationController: 0x7ff91000f000&gt; 的视图控制器 &lt;UITableViewController: 0x7ff91080a700&gt;。” (3认同)