ios - 应用程序在加载时崩溃并且根本没有调用 `didFinishLaunchingWithOptions`

标签 ios swift firebase

我在现有项目中面临一个奇怪的问题。

从早上开始,我就面临着来自火力基地的一次奇怪的崩溃。

它工作正常,没有任何问题,但从早上开始我就面临这个问题。

崩溃:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The default FIRApp instance must be configured before the default FIRAuthinstance can be initialized. One way to ensure that is to call [FIRApp configure]; (FirebaseApp.configure() in Swift) in the App Delegate's application:didFinishLaunchingWithOptions: (application(_:didFinishLaunchingWithOptions:) in Swift).'



它清楚地表明我需要实现 FirebaseApp.configure()在我的应用程序委托(delegate)中,它自过去 6 个月以来就已经存在。

应用代理代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        Messaging.messaging().delegate = self as? MessagingDelegate
        self.getRegisterForRemoteNotifications(application)
        return true
    }

你们可以看到 didFinishLaunchingWithOptions 中已经调用了 Firebase 配置应用启动时仍面临崩溃问题。

我观察到我的 appdelegate didFinishLaunchingWithOptions方法不调用并且它使我的应用程序崩溃。

编辑:

View Controller 代码:
var authUI: FUIAuth!

override func viewDidLoad() {
        super.viewDidLoad()
        authUI = FUIAuth.defaultAuthUI()
        authUI?.delegate = self

        if authUI.auth?.currentUser != nil {
            self.checkAdminUser()
            self.getFavPlace()
        }

}

编辑2:

崩溃堆栈跟踪:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The default FIRApp instance must be configured before the default FIRAuthinstance can be initialized. One way to ensure that is to call [FIRApp configure]; (FirebaseApp.configure() in Swift) in the App Delegate's application:didFinishLaunchingWithOptions: (application(_:didFinishLaunchingWithOptions:) in Swift).' * First throw call stack: ( 0 CoreFoundation 0x00007fff23c7127e exceptionPreprocess + 350 1 libobjc.A.dylib
0x00007fff513fbb20 objc_exception_throw + 48 2 CoreFoundation
0x00007fff23c710bc +[NSException raise:format:] + 188 3 Herrd
0x000000010559e826 +[FIRAuth auth] + 118 4 Herrd
0x00000001054fe84d $s5Herrd23TopicNewsViewControllerC5coderACSgSo7NSCoderC_tcfc + 605 5 Herrd 0x00000001054feaa3 $s5Herrd23TopicNewsViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 51 6 UIKitCore 0x00007fff47cf7268 -[UIClassSwapper initWithCoder:] + 2427 7 UIFoundation 0x00007fff4753d872 UINibDecoderDecodeObjectForValue + 744 8
UIFoundation 0x00007fff4753db19 UINibDecoderDecodeObjectForValue + 1423 9 UIFoundation
0x00007fff4753d57d -[UINibDecoder decodeObjectForKey:] + 251 10 UIKitCore 0x00007fff47cf6531 -[NSCoder(UIIBDependencyInjectionInternal) _decodeObjectsAndTrackChildViewControllerIndexWithParent:forKey:] + 298 11 UIKitCore 0x00007fff47a0e65d -[UIViewController initWithCoder:] + 1419 12 UIKitCore 0x00007fff4795cc16 -[UINavigationController initWithCoder:] + 65 13 UIFoundation 0x00007fff4753d872 UINibDecoderDecodeObjectForValue + 744 14 UIFoundation
0x00007fff4753db19 UINibDecoderDecodeObjectForValue + 1423 15 UIFoundation 0x00007fff4753d57d -[UINibDecoder decodeObjectForKey:] + 251 16 UIKitCore
0x00007fff47cf6531 -[NSCoder(UIIBDependencyInjectionInternal) _decodeObjectsAndTrackChildViewControllerIndexWithParent:forKey:] + 298 17 UIKitCore 0x00007fff47a0e65d -[UIViewController initWithCoder:] + 1419 18 UIKitCore 0x00007fff4793fbed -[UITabBarController initWithCoder:] + 65 19 UIKitCore 0x00007fff47cf7268 -[UIClassSwapper initWithCoder:] + 2427 20 UIFoundation 0x00007fff4753d872 UINibDecoderDecodeObjectForValue + 744 21 UIFoundation 0x00007fff4753d57d -[UINibDecoder decodeObjectForKey:] + 251 22 UIKitCore
0x00007fff47cfb56f -[UIRuntimeConnection initWithCoder:] + 125 23 UIFoundation 0x00007fff4753d872 UINibDecoderDecodeObjectForValue + 744 24 UIFoundation
0x00007fff4753db19 UINibDecoderDecodeObjectForValue + 1423 25 UIFoundation 0x00007fff4753d57d -[UINibDecoder decodeObjectForKey:] + 251 26 UIKitCore
0x00007fff47cf6336 -[NSCoder(UIIBDependencyInjectionInternal) _decodeObjectsWithSourceSegueTemplate:creator:sender:forKey:] + 450 27 UIKitCore 0x00007fff47cf90a5 -[UINib instantiateWithOwner:options:] + 1145 28 UIKitCore
0x00007fff481f8f24 -[UIStoryboard __reallyInstantiateViewControllerWithIdentifier:creator:storyboardSegueTemplate:sender:] + 279 29 UIKitCore 0x00007fff481f8dcf -[UIStoryboard _instantiateViewControllerWithIdentifier:creator:storyboardSegueTemplate:sender:] + 97 30 UIKitCore 0x00007fff48091ebf -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 167 31 UIKitCore 0x00007fff48092473 -[UIApplication _loadMainInterfaceFile] + 274 32 UIKitCore 0x00007fff48090dff -[UIApplication _runWithMainScene:transitionContext:completion:] + 964 33 UIKitCore 0x00007fff477c576d -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 122 34 UIKitCore 0x00007fff47cb44c1 _UIScenePerformActionsWithLifecycleActionMask + 83 35 UIKitCore 0x00007fff477c627f __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 198 36 UIKitCore 0x00007fff477c5c8e -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 296 37 UIKitCore 0x00007fff477c60ac -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 818 38 UIKitCore 0x00007fff477c5941 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 345 39 UIKitCore 0x00007fff477c9f3f __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke_2 + 178 40 UIKitCore 0x00007fff47bd8c83 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 865 41 UIKitCore
0x00007fff47cd2dff _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 240 42 UIKitCore 0x00007fff477c9c5a __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 153 43 UIKitCore 0x00007fff47cd2d02 _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext + 84 44 UIKitCore 0x00007fff477c9ac8 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 381 45 UIKitCore 0x00007fff476206e7 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 657 46 UIKitCore 0x00007fff4761f26c -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 248 47 UIKitCore 0x00007fff47620411 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 210 48 UIKitCore 0x00007fff4808f599 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 535 49 UIKitCore 0x00007fff47bfa7f5 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361 50 FrontBoardServices 0x00007fff365d6165 -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 442 51 FrontBoardServices 0x00007fff365fc4d8 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102 52 FrontBoardServices 0x00007fff365e0c45 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220 53 FrontBoardServices 0x00007fff365fc169 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355 54 libdispatch.dylib 0x000000010a31dd48 _dispatch_client_callout + 8 55 libdispatch.dylib 0x000000010a320cb9 _dispatch_block_invoke_direct + 300 56 FrontBoardServices 0x00007fff3662237e __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK
+ 30 57 FrontBoardServices 0x00007fff3662206c -[FBSSerialQueue _queue_performNextIfPossible] + 441 58 FrontBoardServices 0x00007fff3662257b -[FBSSerialQueue _performNextFromRunLoopSource] + 22 59 CoreFoundation 0x00007fff23bd4471 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 60 CoreFoundation 0x00007fff23bd439c __CFRunLoopDoSource0 + 76 61 CoreFoundation 0x00007fff23bd3b74 __CFRunLoopDoSources0 + 180 62 CoreFoundation
0x00007fff23bce87f __CFRunLoopRun + 1263 63 CoreFoundation
0x00007fff23bce066 CFRunLoopRunSpecific + 438 64 GraphicsServices
0x00007fff384c0bb0 GSEventRunModal + 65 65 UIKitCore
0x00007fff48092d4d UIApplicationMain + 1621 66 Herrd
0x000000010552eb0b main + 75 67 libdyld.dylib
0x00007fff5227ec25 start + 1 68 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException



非常感谢任何帮助或指导!

最佳答案

最后,我找到了为什么我的应用程序崩溃而不调用 appDidFinshLaunching() .

它是由于 TabViewController 之一尝试在 FirebaseApp.configure() 之前获取当前用户详细信息从应用委托(delegate)调用。

其直接定义如下。

let user = FIRAuth().auth.currentUser

因此,它正在崩溃。

我把它放在 viewDidLoad() 下方法,现在该应用程序运行良好,没有任何崩溃。

感谢大家的快速回复并指导我。

希望此信息对其他人有所帮助!

关于ios - 应用程序在加载时崩溃并且根本没有调用 `didFinishLaunchingWithOptions`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60212857/

相关文章:

objective-c - 拖动 UIImages 到选中区域

objective-c - 将 Objective-C memcpy 转换为 Swift

ios - 如何创造橡皮筋效果?

ios - Flutter + Firebase 抛出未处理的异常 : This widget has been unmounted Error Using Navigator to change view

ios - Swift - 搜索总是在全文之前执行

android - 无法为抽象类 'GoogleServicesTask' 创建代理类。与 'com.google.gms:google-services:4.3.4'

ios - 应该如何处理分页 UIScrollView 中的多个委托(delegate)

android - 有没有办法在用户登录后更改应用程序名称和应用程序图标?

ios - 是否有可能在2011年以编程方式获取iphone的电话号码?

linux - NSSet(数组: myArray) works on OS X but crashes in Ubuntu