【问题标题】:App crashing on load and its not calling `didFinishLaunchingWithOptions` at all应用程序在加载时崩溃并且根本没有调用`didFinishLaunchingWithOptions`
【发布时间】:2020-05-29 10:59:39
【问题描述】:

我在现有项目中遇到了一个奇怪的问题。

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

它运行良好,没有任何问题,但从早上开始我就遇到了这个问题。

崩溃:

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

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

AppDelegate 代码:

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

你们可以看到 Firebase Configure 已经在 didFinishLaunchingWithOptions 中调用,但在应用启动时仍然面临崩溃问题。

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

编辑:

视图控制器代码:

var authUI: FUIAuth!

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

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

}

编辑2:

崩溃堆栈跟踪:

* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“默认 FIRApp 必须先配置实例,然后才能使用默认的 FIRAuthinstance 初始化。确保这一点的一种方法是致电[FIRApp configure];FirebaseApp.configure() 在 Swift 中)在 App Delegate 的 application:didFinishLaunchingWithOptions:application(_:didFinishLaunchingWithOptions:) 斯威夫特)。 * 第一次抛出调用堆栈:( 0 CoreFoundation 0x00007fff23c7127e exceptionPreprocess + 350 1 libobjc.A.dylib
0x00007fff513fbb20 ob​​jc_exception_throw + 48 2 核心基础
0x00007fff23c710bc +[NSException raise:format:] + 188 3 Herrd
0x000000010559e826 +[FIRAuth auth] + 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 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 场景:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 657 46 UIKitCore 0x00007fff4761f26c -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 248 47 UIKitCore 0x00007fff47620411 -[UIScene 场景:didUpdateWithDiff:transitionContext:completion:] + 210 48 UIKitCore 0x00007fff4808f599 -[UIApplication 工作区:didCreateScene:withTransitionContext:completion:] + 535 49 UIKitCore 0x00007fff47bfa7f5 -[UIApplicationSceneClientAgent 场景:didInitializeWithEvent:completion:] + 361 50 FrontBoardServices 0x00007fff365d6165 -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 442 51 FrontBoardServices 0x00007fff365fc4d8 __86-[FBSWorkspaceScenesClient 场景ID: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 前板服务 0x00007fff3662237e __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK
+ 30 57 FrontBoardServices 0x00007fff3662206c -[FBSSerialQueue _queue_performNextIfPossible] + 441 58 FrontBoardServices 0x00007fff3662257b -[FBSSerialQueue _performNextFromRunLoopSource] + 22 59 核心基础 0x00007fff23bd4471 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 60 核心基础 0x00007fff23bd439c __CFRunLoopDoSource0 + 76 61 CoreFoundation 0x00007fff23bd3b74 __CFRunLoopDoSources0 + 180 62 CoreFoundation
0x00007fff23bce87f __CFRunLoopRun + 1263 63 核心基础
0x00007fff23bce066 CFRunLoopRunSpecific + 438 64 图形服务
0x00007fff384c0bb0 GSEventRunModal + 65 65 UIKitCore
0x00007fff48092d4d UIApplicationMain + 1621 66 Herrd
0x000000010552eb0b 主 + 75 67 libdyld.dylib
0x00007fff5227ec25 开始 + 1 68 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: 终止于 NSException 类型的未捕获异常

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

【问题讨论】:

  • 您在哪里以及如何初始化您的 FIRAuthinstance?您能想到您最近对代码所做的任何更改,涉及 FIRAuth 吗?
  • 在我的第一个视图控制器中,我像这样使用var authUI: FUIAuth!
  • 不,我不这么认为,所以我使用或更新了 FIRAuth 之类的东西。
  • 嗯,好的。错误消息告诉您身份验证初始化有问题。你能发布一些代码吗?
  • 在你的初始视图控制器中

标签: ios swift firebase


【解决方案1】:

最后,我找到了为什么我的应用程序崩溃并且没有调用appDidFinshLaunching()

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

其直接定义如下。

let user = FIRAuth().auth.currentUser

因此,它正在崩溃。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多