当没有网络连接时,iOS 应用程序在启动时崩溃

标签 ios swift networking crash nib

正如标题所示,如果没有打开互联网连接/飞行模式,我的应用程序在运行时会立即崩溃。问题是,当我设置断点时,它甚至没有到达我的任何代码。没有调用任何 viewDidLoad 甚至 AppDelegate 函数,并且错误消息似乎与没有网络连接无关:

2019-03-21 10:30:20.193955-0500 AppName[98957:977030] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <bundleFilePath> (loaded)' with name 'BYZ-38-t0r-view-8bC-Xf-vdC''

(出于隐私考虑,我显然在其中插入了一些虚假值)

调用堆栈:

*** First throw call stack:
(
0   CoreFoundation                      0x00000001036cb1bb __exceptionPreprocess + 331
1   libobjc.A.dylib                     0x0000000102c69735 objc_exception_throw + 48
2   CoreFoundation                      0x00000001036cb015 +[NSException raise:format:] + 197
3   UIKitCore                           0x00000001088edd94 -[UINib instantiateWithOwner:options:] + 497
4   UIKitCore                           0x0000000108661452 -[UIViewController _loadViewFromNibNamed:bundle:] + 383
5   UIKitCore                           0x0000000108661ddc -[UIViewController loadView] + 177
6   UIKitCore                           0x00000001086620ee -[UIViewController loadViewIfRequired] + 175
7   UIKitCore                           0x0000000108662940 -[UIViewController view] + 27
8   UIKitCore                           0x000000010858134c -[UIPresentationController __sizeClassPair] + 62
9   UIKitCore                           0x0000000108675428 -[UIViewController _presentViewController:withAnimationController:completion:] + 2300
10  UIKitCore                           0x000000010867874b __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 99
11  UIKitCore                           0x0000000108678dd9 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511
12  UIKitCore                           0x00000001086786b1 -[UIViewController _presentViewController:animated:completion:] + 173
13  UIKitCore                           0x00000001086789f0 -[UIViewController presentViewController:animated:completion:] + 150
14  AppName                        0x0000000100f1125e $SSo16UIViewControllerC12DataScoutProE27showDismissiveAlertMesssage7messageySS_tF + 254
15  AppName                        0x0000000100e58a97 $S12AppName18HomeViewControllerC10commonInit33_90D4AB13D5DB6EAFA2D0742F81F552BALLyyF + 727
16  AppName                        0x0000000100e58462 $S12AppName18HomeViewControllerC5coderACSgSo7NSCoderC_tcfc + 146
17  AppName                        0x0000000100e584df $S12AppName18HomeViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 47
18  UIKitCore                           0x00000001088ec166 -[UIClassSwapper initWithCoder:] + 246
19  UIFoundation                        0x000000010c8f35ad UINibDecoderDecodeObjectForValue + 749
20  UIFoundation                        0x000000010c8f32b3 -[UINibDecoder decodeObjectForKey:] + 251
21  UIKitCore                           0x00000001088f07b8 -[UIRuntimeConnection initWithCoder:] + 178
22  UIFoundation                        0x000000010c8f35ad UINibDecoderDecodeObjectForValue + 749
23  UIFoundation                        0x000000010c8f3854 UINibDecoderDecodeObjectForValue + 1428
24  UIFoundation                        0x000000010c8f32b3 -[UINibDecoder decodeObjectForKey:] + 251
25  UIKitCore                           0x00000001088ee067 -[UINib instantiateWithOwner:options:] + 1220
26  UIKitCore                           0x0000000108e228b6 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 181
27  UIKitCore                           0x0000000108c8103a -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 112
28  UIKitCore                           0x0000000108c8150c -[UIApplication _loadMainInterfaceFile] + 272
29  UIKitCore                           0x0000000108c7fb25 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1357
30  UIKitCore                           0x000000010849e4e9 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 866
31  UIKitCore                           0x00000001084a729c +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
32  UIKitCore                           0x000000010849e126 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 233
33  UIKitCore                           0x000000010849eae0 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 1085
34  UIKitCore                           0x000000010849ccb5 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 795
35  UIKitCore                           0x000000010849c95f -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 435
36  UIKitCore                           0x00000001084a1a90 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 584
37  UIKitCore                           0x00000001084a280e _performActionsWithDelayForTransitionContext + 100
38  UIKitCore                           0x00000001084a17ef -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 221
39  UIKitCore                           0x00000001084a693a -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
40  UIKitCore                           0x0000000108c7e44e -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 515
41  UIKitCore                           0x0000000108822d09 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 357
42  FrontBoardServices                  0x000000010f55e2da -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 448
43  FrontBoardServices                  0x000000010f569443 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 271
44  FrontBoardServices                  0x000000010f568b3a __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 53
45  libdispatch.dylib                   0x000000010548a602 _dispatch_client_callout + 8
46  libdispatch.dylib                   0x000000010548db78 _dispatch_block_invoke_direct + 301
47  FrontBoardServices                  0x000000010f59dba8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
48  FrontBoardServices                  0x000000010f59d860 -[FBSSerialQueue _performNext] + 457
49  FrontBoardServices                  0x000000010f59de40 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
50  CoreFoundation                      0x0000000103630721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
51  CoreFoundation                      0x000000010362ff93 __CFRunLoopDoSources0 + 243
52  CoreFoundation                      0x000000010362a63f __CFRunLoopRun + 1263
53  CoreFoundation                      0x0000000103629e11 CFRunLoopRunSpecific + 625
54  GraphicsServices                    0x000000010c5b71dd GSEventRunModal + 62
55  UIKitCore                           0x0000000108c8181d UIApplicationMain + 140
56  AppName                        0x0000000100e8e794 main + 68
57  libdyld.dylib                       0x0000000105500575 start + 1
)

我真的不知道它会是什么。尝试在 [UIViewController _loadViewFromNibNamed:bundle:] 设置符号断点,但这并没有真正提供任何有用的见解。希望有人能帮忙。我还应该提到我在 AppDelegate 中所做的唯一一件事就是实例化 firebase。

最佳答案

reddit 上的一个乐于助人的人帮我解决了这个问题。没有意识到,但我的初始 View Controller 上有一个 init() 函数,最后一个人制作的函数检查了互联网连接,如果没有,则重定向到另一个页面。

关于当没有网络连接时,iOS 应用程序在启动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55284699/

相关文章:

swift - 尝试附加/替换数组元素时“对成员映射的歧义引用”

c# - 套接字客户端关闭连接而服务器不知道这一点会发生吗?

networking - httpclient使用什么端口?

ios - 带有持续时间的 UIView.animate 无法正常工作

python - 在应用程序中嵌入远程 Python shell

ios - 如何在冷启动时将 iOS 7 应用程序恢复到 ViewController

ios - PFLoginViewController 不使用 Swift 显示 Facebook 登录按钮

ios - 每次加载时间表时双击功能都会累积

ios - iOS 和 Android 的 AWS Pinpoint 推送通知传送问题

ios - 在 swift : how to add tab bar icons to a regular ViewController storyboard?