添加URL Scheme时Xcode崩溃问题求助
问题描述
通过Target→Info→URL Types给Xcode项目添加新URL Scheme时,每次操作都会导致Xcode崩溃,同事的设备也出现同样问题。其他项目执行相同操作无异常,对比构建设置未发现明显差异。
直接编辑Info.plist添加Scheme可行,但Xcode本身操作不应崩溃。同时App内URL相关行为异常——AppDelegate对应方法未按预期调用,怀疑是项目配置问题。
Info.plist相关片段
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>com.googleusercontent.apps.{app_id_left_out_for_this_post}</string> </array> </dict> </array>
Xcode崩溃详情
Translated Report (Full Report Below) Process: Xcode [1516] Path: /Applications/Xcode.app/Contents/MacOS/Xcode Identifier: com.apple.dt.Xcode Version: 14.3 (21812) Build Info: IDEFrameworks-21812000000000000~3 (14E222b) App Item ID: 497799835 App External ID: 855820377 Code Type: ARM-64 (Native) Parent Process: launchd [1] User ID: 501 Date/Time: 2023-05-03 17:33:55.8846 +0200 OS Version: macOS 13.3.1 (22E772610a) Report Version: 12 Anonymous UUID: E1F9FAB3-74AA-9387-B8D9-CFC697705C5E Time Awake Since Boot: 1300 seconds System Integrity Protection: enabled Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Application Specific Information: abort() called Application Specific Signatures: NSInvalidArgumentException Application Specific Backtrace 0: 0 CoreFoundation 0x000000019e5ef19c __exceptionPreprocess + 176 1 DVTFoundation 0x0000000104483d84 DVTFailureHintExceptionPreprocessor + 392 2 libobjc.A.dylib 0x000000019e10e4d4 objc_exception_throw + 60 3 Foundation 0x000000019f56d2cc +[NSDirectorySubpathsOperation directorySubpathsOperationAtPath:] + 0 4 Xcode3UI 0x0000000138ef2ec0 -[Xcode3InfoEditorIconNameProvider listContents] + 384 5 Foundation 0x000000019f4c0110 -[NSObject(NSKeyValueCoding) valueForKey:] + 320 6 Foundation 0x000000019f4bff78 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 220 7 Foundation 0x000000019f4bff78 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 220 8 Foundation 0x000000019f526bcc -[NSDictionary(NSKeyValueCoding) valueForKeyPath:] + 404 9 Foundation 0x000000019f4bff78 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 220 10 Foundation 0x000000019f4bff78 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 220 11 IDEKit 0x0000000107e7f534 __IDEInspectorSingleValueForKeyPath_block_invoke_2 + 144 12 IDEKit 0x0000000107e7edac IDEInspectorEnumerateContent + 424 13 IDEKit 0x0000000107e7f39c IDEInspectorSingleValueForKeyPath + 244 14 IDEKit 0x0000000107bb7fb0 -[IDEInspectorListProperty refresh] + 140 15 IDEKit 0x0000000107ba457c -[IDEInspectorProperty performRefresh] + 208 16 IDEKit 0x0000000107ba2da0 __65-[IDEInspectorProperty initWithPropertyDefinition:andController:]_block_invoke + 16 17 DVTFoundation 0x00000001042d4160 -[DVTDelayedInvocation runBlock:] + 204 18 IDEKit 0x0000000107e49018 -[IDEInspectorPropertyLayoutGroup refreshIfNeeded] + 64 19 IDEKit 0x0000000107e44c60 -[IDEInspectorLayoutGroup refreshIfNeeded] + 164 20 IDEKit 0x0000000107e44c60 -[IDEInspectorLayoutGroup refreshIfNeeded] + 164 21 IDEKit 0x0000000107e44c60 -[IDEInspectorLayoutGroup refreshIfNeeded] + 164 22 IDEKit 0x0000000107e44c60 -[IDEInspectorLayoutGroup refreshIfNeeded] + 164 23 IDEKit 0x0000000107e44c60 -[IDEInspectorLayoutGroup refreshIfNeeded] + 164 24 IDEKit 0x0000000107e44c60 -[IDEInspectorLayoutGroup refreshIfNeeded] + 164 25 IDEKit 0x0000000107e44c60 -[IDEInspectorLayoutGroup refreshIfNeeded] + 164 26 IDEKit 0x0000000107e44c60 -[IDEInspectorLayoutGroup refreshIfNeeded] + 164 27 IDEKit 0x0000000107e40a1c -[IDEInspectorContentView layoutTopDown] + 40 28 DVTStructuredLayoutKit 0x0000000103cec0c4 +[DVTStructuredLayoutViewCoordinator sendConfigureSubviewsToView:populatingLaidOutLayoutViews:] + 164 29 DVTStructuredLayoutKit 0x0000000103cec344 -[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:] + 256 30 DVTStructuredLayoutKit 0x0000000103cec5b8 __199-[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:]_block_invoke + 196 31 DVTFoundation 0x0000000104483a10 DVTInvokeWithFailureHintProvider + 76 32 DVTStructuredLayoutKit 0x0000000103cec424 -[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:] + 480 33 DVTStructuredLayoutKit 0x0000000103cec5b8 __199-[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:]_block_invoke + 196 34 DVTFoundation 0x0000000104483a10 DVTInvokeWithFailureHintProvider + 76 35 DVTStructuredLayoutKit 0x0000000103cec424 -[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:] + 480 36 DVTStructuredLayoutKit 0x0000000103cec5b8 __199-[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:]_block_invoke + 196 37 DVTFoundation 0x0000000104483a10 DVTInvokeWithFailureHintProvider + 76 38 DVTStructuredLayoutKit 0x0000000103cec424 -[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:] + 480 39 DVTStructuredLayoutKit 0x0000000103cec5b8 __199-[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:]_block_invoke + 196 40 DVTFoundation 0x0000000104483a10 DVTInvokeWithFailureHintProvider + 76 41 DVTStructuredLayoutKit 0x0000000103cec424 -[DVTStructuredLayoutViewCoordinator recursivelyLayoutSubviewsOfView:populatingVisitedViews:populatingVisitedLayoutViewsInTopDownOrder:populatingLaidOutLayoutViews:currentLayoutPass:needsSecondPass:] + 480
分析与解决方案
从崩溃栈来看,崩溃触发在-[Xcode3InfoEditorIconNameProvider listContents]调用NSDirectorySubpathsOperation时抛出NSInvalidArgumentException,说明Xcode刷新Info编辑器时,尝试访问某个图标资源目录失败,大概率是项目图标配置存在异常。
1. 检查图标资源配置
- 打开
Assets.xcassets,确认所有图标集完整,无缺失或损坏的文件 - 检查
Info.plist中CFBundleIcons、CFBundleIconFiles等图标相关字段,排查是否存在无效路径或未替换的占位符(比如{app_id_left_out_for_this_post}这类标记)
2. 清理Xcode缓存
关闭Xcode,执行以下命令清理缓存:
rm -rf ~/Library/Developer/Xcode/DerivedData rm -rf ~/Library/Caches/com.apple.dt.Xcode
重启Xcode后再尝试添加URL Scheme。
3. 重置Xcode偏好设置
关闭Xcode,运行:
defaults delete com.apple.dt.Xcode
重启Xcode后重新配置URL Types,避免偏好设置冲突导致崩溃。
4. 排查项目配置差异
- 创建全新空项目,对比其
project.pbxproj和Info.plist,找出当前项目中可能存在的异常配置项 - 尝试将当前项目的代码和资源逐步迁移到新项目中,定位导致崩溃的具体配置
5. 更换Xcode版本
当前使用的Xcode 14.3可能存在已知bug,试试升级到14.3.1或更高稳定版,或者降级到14.2版本,验证崩溃是否消失。
关于URL异常行为的排查
- 确认直接编辑Info.plist添加的Scheme格式正确,
CFBundleTypeRole设为Editor是合理配置,无需修改 - 检查AppDelegate的
application(_:open:options:)或SceneDelegate的scene(_:openURLContexts:)方法,确保逻辑正确无遗漏 - 在模拟器中用命令测试URL唤起:
xcrun simctl openurl booted <你的Scheme>://test,验证是否能正常唤起App并触发对应方法
内容的提问来源于stack exchange,提问作者Jorn Rigter
相关产品推荐
相关产品推荐

