在使用Xcode 13构建后,iOS 12及以下版本的应用程序崩溃。

3

一款在iOS 9-15上成功运行的应用程序,在使用Xcode 13.1(在M1 Pro上升级后)构建时,在iOS 9-12上启动时崩溃。

由于使用了仅存在于iOS 13+上的UITabBarAppearance,因此在主storyboard解档时崩溃(请参见下面的跟踪)。我的storyboard入口点是一个Tab Bar控制器。

自从以前的Xcode版本中在iOS 9-15上工作时,我没有编辑过我的storyboard文件,而且崩溃发生在我的任何代码运行之前。

希望这只是模拟器问题(我没有旧的iOS设备),我将其上传到商店,但该应用程序在iOS 12及以下的真实设备上启动时也会崩溃。https://apps.apple.com/nz/app/campermate-australia-nz/id1586561660

最低OS目标为9.0。我们可以放弃对iOS 9-11的支持,但我们仍然有许多iPhone 6和5用户(他们仅限于iOS 12)。

我该如何解决这个问题?

2021-12-15 10:51:09.526554+1300 TTG_Explore_Australia[36783:2248622] libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.
2021-12-15 10:51:09.954515+1300 TTG_Explore_Australia[36783:2248622] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named UITabBarAppearance because no class named UITabBarAppearance was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000113cae8db __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x0000000113259ac5 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000113cae735 +[NSException raise:format:] + 197
    3   UIFoundation                        0x00000001176626c9 UINibDecoderDecodeObjectForValue + 360
    4   UIFoundation                        0x0000000117662af9 UINibDecoderDecodeObjectForValue + 1432
    5   UIFoundation                        0x0000000117662554 -[UINibDecoder decodeObjectForKey:] + 251
    6   UIKitCore                           0x000000011ca0c827 -[UINib instantiateWithOwner:options:] + 1306
    7   UIKitCore                           0x000000011cf28594 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 181
    8   UIKitCore                           0x000000011cd8c809 -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 111
    9   UIKitCore                           0x000000011cd8ccb1 -[UIApplication _loadMainInterfaceFile] + 274
    10  UIKitCore                           0x000000011cd8b3e5 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1360
    11  UIKitCore                           0x000000011c5cfa4e __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 904
    12  UIKitCore                           0x000000011c5d8346 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
    13  UIKitCore                           0x000000011c5cf664 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
    14  UIKitCore                           0x000000011c5cffc0 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 1091
    15  UIKitCore                           0x000000011c5ce332 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 782
    16  UIKitCore                           0x000000011c5cdfe9 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
    17  UIKitCore                           0x000000011c5d2d2e __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 576
    18  UIKitCore                           0x000000011c5d3988 _performActionsWithDelayForTransitionContext + 100
    19  UIKitCore                           0x000000011c5d2a95 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
    20  UIKitCore                           0x000000011c5d7a48 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
    21  UIKitCore                           0x000000011cd89dc8 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 514
    22  UIKitCore                           0x000000011c94102f -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
    23  FrontBoardServices                  0x000000011aeb4d25 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 448
    24  FrontBoardServices                  0x000000011aebead6 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 283
    25  FrontBoardServices                  0x000000011aebe300 __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 53
    26  libdispatch.dylib                   0x0000000114cc4db5 _dispatch_client_callout + 8
    27  libdispatch.dylib                   0x0000000114cc82ba _dispatch_block_invoke_direct + 300
    28  FrontBoardServices                  0x000000011aef00da __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    29  FrontBoardServices                  0x000000011aeefd92 -[FBSSerialQueue _performNext] + 451
    30  FrontBoardServices                  0x000000011aef0327 -[FBSSerialQueue _performNextFromRunLoopSource] + 42
    31  CoreFoundation                      0x0000000113c15db1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    32  CoreFoundation                      0x0000000113c15633 __CFRunLoopDoSources0 + 243
    33  CoreFoundation                      0x0000000113c0fcef __CFRunLoopRun + 1231
    34  CoreFoundation                      0x0000000113c0f4d2 CFRunLoopRunSpecific + 626
    35  GraphicsServices                    0x00000001169e62fe GSEventRunModal + 65
    36  UIKitCore                           0x000000011cd8cfc2 UIApplicationMain + 140
    37  TTG_Explore_Australia               0x0000000100e63dd8 main + 104
    38  ???                                 0x0000000202b024fe 0x0 + 8635032830
    39  ???                                 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named UITabBarAppearance because no class named UITabBarAppearance was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)'
terminating with uncaught exception of type NSException
CoreSimulator 776.4 - Device: iPhone 8 Plus (B0A6FB7E-392D-40E7-AC7C-B6AF109ABE60) - Runtime: iOS 12.4 (16G73) - DeviceType: iPhone 8 Plus
3个回答

3
在堆栈跟踪的底部,它表示:
未捕获异常'NSInvalidUnarchiveOperationException'终止应用程序,原因是'无法实例化名为UITabBarAppearance的类,因为找不到名为UITabBarAppearance的类; 该类需要在源代码中定义或从库中链接(确保该类是正确目标的一部分)'。 异常类型终止。 UITabBarAppearance在iOS 13中引入,因此在旧版本的iOS上无法使用。 检查你的代码是否有任何关于UITabBarAppearance的出现,如果有,请将其删除或包裹在if #available中。 这也可能是故事板内部使用了UITabBarAppearance的问题。

1
谢谢,它在故事板文件中(见下文),我没想到我已经改过了,但是XCode改了!我已经在整个项目中搜索了UITabBarAppearance,但在故事板XML中它只是tabBarAppearance。 - Bruce Webster
@BruceWebster 没问题。您能否点击绿色复选标记接受我的答案或您自己的答案?这将使未来有相同问题的人更容易找到他们所需要的答案。 - aheze

2
XCode偷偷地在我的故事板文件中插入了这些,我毫不知情!
<tabBarAppearance key="standardAppearance"/>

并且

<navigationBarAppearance key="standardAppearance"/>

删除它们解决了问题!我在代码中设置了iOS13+的外观,并进行了版本检查。


我在Xcode中哪里可以找到这些行? - Sakshi Singh
@SakshiSingh 我在XCode中没有找到它们。 我打开了MainStoryboard.storyboard文件并使用文本编辑器删除了这两个键。请注意保持xml有效或使用xml编辑器。 - Bruce Webster

0
我通过在构建阶段中手动将LinkPresentation.framework添加到“链接二进制文件库”,并将其状态设置为可选项来解决了这个问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接