如果应用程序will / didFinishLaunching方法存在,Mac Catalyst应用程序在启动时会崩溃

问题描述 投票:0回答:1

我这里有一个很奇怪的问题。

我的Mac Catalyst应用启动时崩溃,但AppDelegate.swift中出现以下异常:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: title)'

某些信息是该项目是从existing iOS / iPadOS应用程序移植的Mac Catalyst应用程序,并且它not使用SwiftUI,并且not使用多个场景。该异常发生在AppDelegate类中。

但是,调试器指向类声明的行,而不是我编写的任何代码,因此,我认为这是内部错误。

有趣的是,我已经研究了一下,并确定从我从AppDelegate中删除application(_:willFinishLaunchingWithOptions:)application(_:didFinishLaunchingWithOptions:)方法的那一刻起,该应用程序就运行良好。甚至像这样的空声明:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    return true
}

将导致应用程序崩溃,而根本不包括该方法将允许应用程序正常运行。

这里是堆栈跟踪:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: title)'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff35ac5d07 __exceptionPreprocess + 250
    1   libobjc.A.dylib                     0x00007fff6e7ea5bf objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff35b7463e -[__NSCFString characterAtIndex:].cold.1 + 0
    3   CoreFoundation                      0x00007fff35b7f19c -[__NSDictionaryM setObject:forKey:].cold.3 + 0
    4   CoreFoundation                      0x00007fff35a03459 -[__NSDictionaryM setObject:forKey:] + 976
    5   UIKitCore                           0x00007fff764748eb -[_UIMenuBarItem properties] + 99
    6   UIKitMacHelper                      0x00007fff66bf872a UINSNSMenuItemFromUINSMenuItem + 90
    7   UIKitMacHelper                      0x00007fff66bf8340 _insertUINSMenuItemsIntoNSMenu + 1135
    8   UIKitMacHelper                      0x00007fff66bf7da8 UINSNSMenuFromUINSMenu + 119
    9   UIKitMacHelper                      0x00007fff66bf7c49 -[UINSMenuController _createNSMenu:forContextMenu:] + 79
    10  UIKitMacHelper                      0x00007fff66bf7b09 -[UINSMenuController setMainMenuBar:] + 70
    11  UIKitCore                           0x00007fff764687d6 -[_UIMenuBarController _rebuildRootCommandGroup] + 229
    12  UIKitCore                           0x00007fff763113a2 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 801
    13  UIKitCore                           0x00007fff76310a33 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 5775
    14  UIKitCore                           0x00007fff7630de2b -[UIApplication _runWithMainScene:transitionContext:completion:] + 1319
    15  UIKitCore                           0x00007fff7630d7fb -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 122
    16  UIKitCore                           0x00007fff76308a07 _UIScenePerformActionsWithLifecycleActionMask + 83
    17  UIKitCore                           0x00007fff7630cf45 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 198
    18  UIKitCore                           0x00007fff7630cd28 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 467
    19  UIKitCore                           0x00007fff7630bf21 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 823
    20  UIKitCore                           0x00007fff7630bb42 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 350
    21  UIKitCore                           0x00007fff7678e853 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke_2 + 178
    22  UIKitCore                           0x00007fff7630a0a3 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 832
    23  UIKitCore                           0x00007fff763095f2 _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 240
    24  UIKitCore                           0x00007fff763092bf __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 153
    25  UIKitCore                           0x00007fff7630920c _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext + 84
    26  UIKitCore                           0x00007fff76308f4a -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 379
    27  UIKitCore                           0x00007fff763083cb __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 685
    28  UIKitCore                           0x00007fff76307aef -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 262
    29  UIKitCore                           0x00007fff763079a4 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 210
    30  UIKitCore                           0x00007fff762fa3b8 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 524
    31  UIKitCore                           0x00007fff762fa122 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
    32  FrontBoardServices                  0x00007fff5225a25d -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 453
    33  FrontBoardServices                  0x00007fff5225a083 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.156 + 102
    34  FrontBoardServices                  0x00007fff52259f02 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220
    35  FrontBoardServices                  0x00007fff52259b0d __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 354
    36  libdispatch.dylib                   0x000000010091e826 _dispatch_client_callout + 8
    37  libdispatch.dylib                   0x0000000100922070 _dispatch_block_invoke_direct + 289
    38  FrontBoardServices                  0x00007fff52259996 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    39  FrontBoardServices                  0x00007fff52259766 -[FBSSerialQueue _queue_performNextIfPossible] + 441
    40  FrontBoardServices                  0x00007fff52259593 -[FBSSerialQueue _performNextFromRunLoopSource] + 22
    41  CoreFoundation                      0x00007fff35a49f12 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    42  CoreFoundation                      0x00007fff35a49eb1 __CFRunLoopDoSource0 + 103
    43  CoreFoundation                      0x00007fff35a49ccb __CFRunLoopDoSources0 + 209
    44  CoreFoundation                      0x00007fff35a489fa __CFRunLoopRun + 927
    45  CoreFoundation                      0x00007fff35a47ffe CFRunLoopRunSpecific + 462
    46  HIToolbox                           0x00007fff3467babd RunCurrentEventLoopInMode + 292
    47  HIToolbox                           0x00007fff3467b6f4 ReceiveNextEventCommon + 359
    48  HIToolbox                           0x00007fff3467b579 _BlockUntilNextEventMatchingListInModeWithFilter + 64
    49  AppKit                              0x00007fff32cc6c99 _DPSNextEvent + 883
    50  AppKit                              0x00007fff32cc54e0 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
    51  AppKit                              0x00007fff32cb71ee -[NSApplication run] + 658
    52  AppKit                              0x00007fff32c88ff6 NSApplicationMain + 777
    53  AppKit                              0x00007fff32faaa85 _NSApplicationMainWithInfoDictionary + 16
    54  UIKitMacHelper                      0x00007fff66bf4e00 UINSApplicationMain + 322
    55  UIKitCore                           0x00007fff762db6ff UIApplicationMain + 2130
    56  <Project Name>                      0x00000001002222db main + 75
    57  libdyld.dylib                       0x00007fff6f991cc9 start + 1
    58  ???                                 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我无法使用新的Xcode项目来重新创建此问题。

关于如何解决此问题的任何想法?预先感谢。

swift macos appdelegate maccatalyst
1个回答
0
投票

似乎CFBundleName中可能缺少Info.plist

提示在错误中:

[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: title)

© www.soinside.com 2019 - 2024. All rights reserved.