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

从早上开始,我正面临着一次火警事故。

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

崩溃:

***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“默认FIRApp
必须先配置实例,然后才能设置默认FIRAuthinstance
初始化。一种确保方法是调用[FIRApp configure]; (Swift中的FirebaseApp.configure())在应用程序委托的
application:didFinishLaunchingWithOptions: (在Swift中为application(_:didFinishLaunchingWithOptions:))。

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

AppDelegate代码:

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方法未调用,并且崩溃了我的应用程序。

编辑:

ViewController代码:
var authUI: FUIAuth!

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

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

}

编辑2:

崩溃Stacktrace:

*由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“默认FIRApp
必须先配置实例,然后才能设置默认FIRAuthinstance
初始化。一种确保方法是调用[FIRApp configure]; (Swift中的FirebaseApp.configure())在应用程序委托的
application:didFinishLaunchingWithOptions: (在Swift中为application(_:didFinishLaunchingWithOptions:))。
*
第一个抛出调用堆栈:(0 CoreFoundation 0x00007fff23c7127e exceptionPreprocess + 350 1 libobjc.A.dylib
0x00007fff513fbb20 ob​​jc_exception_throw + 48 2 CoreFoundation
0x00007fff23c710bc + [NSException提高:格式:] + 188 3 Herrd
0x000000010559e826 + [FIRAuth身份验证] + 118 4 Herrd
0x00000001054fe84d
$ s5Herrd23TopicNewsViewControllerC5coderACSgSo7NSCoderC_tcfc + 605 5
草稿0x00000001054feaa3
$ s5Herrd23TopicNewsViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 51 6
UIKitCore 0x00007fff47cf7268
-[UIClassSwapper initWithCoder:] + 2427 7 UIFoundation 0x00007fff4753d872 UINibDecoderDecodeObjectForValue + 744 8
UIFoundation 0x00007fff4753db19
UINibDecoderDecodeObjectForValue + 1423 9 UIFoundation
0x00007fff4753d57d-[UINibDecoder encodeObjectForKey:] + 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
encodeObjectForKey:] + 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
encodeObjectForKey:] + 251 22 UIKitCore
0x00007fff47cfb56f-[UIRuntimeConnection initWithCoder:] + 125 23
UIFoundation 0x00007fff4753d872
UINibDecoderDecodeObjectForValue + 744 24 UIFoundation
0x00007fff4753db19 UINibDecoderDecodeObjectForValue + 1423 25
UIFoundation 0x00007fff4753d57d-[UINibDecoder
encodeObjectForKey:] + 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- [UI场景:didUpdateWithDiff:transitionContext:completion:] _ block_invoke +
657 46 UIKitCore 0x00007fff4761f26c
-[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 248 47 UIKitCore 0x00007fff47620411
-[UI场景:didUpdateWithDiff:transitionContext:完成:] + 210 48 UIKitCore 0x00007fff4808f599
-[UIApplication工作区:didCreateScene:withTransitionContext:完成:] + 535 49
UIKitCore 0x00007fff47bfa7f5
-[UIApplicationSceneClientAgent场景:didInitializeWithEvent:完成:] + 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场景ID: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图形服务
0x00007fff384c0bb0 GSEventRunModal + 65 65 UIKitCore
0x00007fff48092d4d UIApplicationMain + 1621 66赫德
0x000000010552eb0b主+ 75 67 libdyld.dylib
0x00007fff5227ec25开始+ 1 68 ???
0x0000000000000001 0x0 +1)libc ++ abi.dylib:终止于
类型为NSException的未捕获异常

任何帮助或指导,不胜感激!

最佳答案

最后,我找到了为什么我的应用程序崩溃而没有调用appDidFinshLaunching()的原因。

这是由于TabViewController之一试图从应用程序委托调用FirebaseApp.configure()之前获取当前用户详细信息。

其直接定义如下。

let user = FIRAuth().auth.currentUser

因此,它崩溃了。

我将其放在viewDidLoad()方法下,现在该应用程序运行正常,没有崩溃。

感谢每个人的快速答复,并为此提供指导。

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

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

10-15 00:51