iOS 16中启动VNDocumentCameraViewController崩溃问题求助
iOS 16 下 VNDocumentCameraViewController 启动崩溃问题排查
问题说明
- 在iOS 16的iPad/iPhone设备上启动
VNDocumentCameraViewController时触发致命错误,iOS 14、iOS 15等旧系统无此问题 - 已在
info.plist中配置NSCameraUsageDescription权限字段 - 崩溃发生在调用
self.present之后,无法正常显示相机界面
触发崩溃的代码
let myScanViewController = VNDocumentCameraViewController() myScanViewController.delegate = self self.present(myScanViewController, animated: false)
崩溃调试信息
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
堆栈回溯日志
0 CoreFoundation 0x18add6248 __exceptionPreprocess + 164 1 libobjc.A.dylib 0x1841a3a68 objc_exception_throw + 60 2 CoreFoundation 0x18af7a6d4 -[__NSCFString characterAtIndex:].cold.1 + 0 3 CoreFoundation 0x18af77a74 -[__NSPlaceholderArray initWithCapacity:].cold.1 + 0 4 CoreFoundation 0x18add1828 -[__NSPlaceholderArray initWithObjects:count:] + 252 5 CoreFoundation 0x18add2b1c +[NSArray arrayWithObjects:count:] + 40 6 UIKitCore 0x18d387f5c +[UIImageSymbolConfiguration configurationWithHierarchicalColor:] + 124 7 UIKitCore 0x18d7ffd60 -[_UIImageCUIVectorGlyphContent _automaticSymbolConfiguration] + 104 8 UIKitCore 0x18cff6434 -[UIImageView _symbolConfigurationForImage:] + 72 9 UIKitCore 0x18cfc77cc -[UIImageView _resolvedImageFromImage:forTrait:] + 96 10 UIKitCore 0x18cf941fc -[UIImageView _resolvedImageFromImage:] + 152 11 UIKitCore 0x18cf92d5c -[UIButtonLegacyVisualProvider intrinsicSizeWithinSize:] + 132 12 UIKitCore 0x18cf92cb4 -[UIButton _intrinsicSizeWithinSize:] + 52 13 UIKitCore 0x18cfcd04c -[UIView(UIConstraintBasedLayout) intrinsicContentSize] + 120 14 UIKitCore 0x18cfcd598 -[UIButton intrinsicContentSize] + 148 15 UIKitCore 0x18cfccbe0 -[UIView _generateContentSizeConstraints] + 52 16 UIKitCore 0x18cfb74a8 -[UIView _updateContentSizeConstraints] + 244 17 UIKitCore 0x18d04b4a4 -[UIView(AdditionalLayoutSupport) _updateSystemConstraints] + 88 18 UIKitCore 0x18d0c9700 -[UIButton updateConstraints] + 72 19 UIKitCore 0x18d04b378 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 348 20 UIKitCore 0x18d04b110 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 764 21 UIKitCore 0x18d04b02c -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 22 UIKitCore 0x18d04b02c -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 23 UIKitCore 0x18d04b02c -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 24 CoreAutoLayout 0x1a72a7e90 -[NSISEngine withBehaviors:performModifications:] + 84 25 UIKitCore 0x18d04ae08 __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 104 26 UIKitCore 0x18cfed6e8 -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 96 27 UIKitCore 0x18cfed350 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 172 28 UIKitCore 0x18cfecf50 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 388 29 UIKitCore 0x18d02cdec -[UIView(Hierarchy) layoutBelowIfNeeded] + 1064 30 DocumentCamera 0x1edf3c6c4 -[ICDocCamViewController initializeUserInterface] + 656 31 DocumentCamera 0x1edf3baa4 -[ICDocCamViewController viewDidLoad] + 1044 32 UIKitCore 0x18d2dd330 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 84 33 UIKitCore 0x18cf750a8 -[UIViewController loadViewIfRequired] + 712 34 UIKitCore 0x18d23c1bc -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 124 35 UIKitCore 0x18d1025ec -[UINavigationController _startTransition:fromViewController:toViewController:] + 196 36 UIKitCore 0x18d101aa4 -[UINavigationController _startDeferredTransitionIfNeeded:] + 608 37 UIKitCore 0x18d1010f4 -[UINavigationController __viewWillLayoutSubviews] + 96 38 UIKitCore 0x18d101058 -[UILayoutContainerView layoutSubviews] + 172 39 UIKitCore 0x18cf5ecec -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1980 40 QuartzCore 0x18c43b4e8 CA::Layer::layout_if_needed(CA::Transaction*) + 500 41 QuartzCore 0x18c44eb9c CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 42 QuartzCore 0x18c460098 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 456 43 QuartzCore 0x18c4973c4 CA::Transaction::commit() + 652 44 QuartzCore 0x18c47e408 CA::Transaction::flush_as_runloop_observer(bool) + 88 45 CoreFoundation 0x18ae5e070 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36 46 CoreFoundation 0x18ade6690 __CFRunLoopDoObservers + 532 47 CoreFoundation 0x18ae47f8c __CFRunLoopRun + 1048 48 CoreFoundation 0x18ae4d1e4 CFRunLoopRunSpecific + 612 49 GraphicsServices 0x1c3c6d368 GSEventRunModal + 164 50 UIKitCore 0x18d2fcd88 -[UIApplication _run] + 888 51 UIKitCore 0x18d2fc9ec UIApplicationMain + 340 52 digitrame 0x1019c8d88 main + 64 53 dyld 0x1a9171948 start + 2504
排查与解决建议
从堆栈日志分析,崩溃根源是UIImageSymbolConfiguration初始化时传入了nil颜色值,导致数组插入nil对象。这通常和全局UIAppearance设置或自定义控件配置冲突有关,可按以下方向排查:
- 检查项目中针对
UIButton、UIImageView或UIImageSymbolConfiguration的全局外观修改,尤其是涉及层级颜色(HierarchicalColor)的设置,确认是否存在传入nil值的情况 - 尝试在启动相机前临时重置全局UIAppearance配置,测试是否能规避崩溃:
// 临时重置按钮相关外观 UIButton.appearance().setTitleColor(nil, for: .normal) UIButton.appearance().setImage(nil, for: .normal) // 启动相机控制器 let myScanViewController = VNDocumentCameraViewController() myScanViewController.delegate = self self.present(myScanViewController, animated: false) - 确认项目中自定义的图片加载逻辑,特别是SF Symbols的处理,避免返回nil的Symbol配置
- 移除所有自定义外观设置,使用系统默认UI配置,验证是否为自定义代码导致的冲突
内容的提问来源于stack exchange,提问作者Pascal
相关产品推荐
相关产品推荐

