You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS快餐订购应用集成CarPlay时API请求/加载器触发崩溃问题

CarPlay集成崩溃问题:未识别选择器-[CPTemplateApplicationScene windows]

问题概述

  • 崩溃触发场景:
    • API请求返回成功时应用崩溃
    • iOS应用内显示加载器时崩溃
  • 核心异常:未捕获NSInvalidArgumentException,错误原因是向CPTemplateApplicationScene实例发送了它无法识别的windows选择器。

完整崩溃调用栈(中文翻译)

*** 应用因未捕获异常'NSInvalidArgumentException'终止,原因:'-[CPTemplateApplicationScene windows]: 无法识别的选择器发送到实例0x172371180' ***
首次抛出调用栈:
(
0 CoreFoundation 0x0000000116f348a8 __exceptionPreprocess + 172
1 libobjc.A.dylib 0x000000010a8c809c objc_exception_throw + 56
2 CoreFoundation 0x0000000116f496f8 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 UIKitCore 0x000000012d8ef3d4 -[UIResponder doesNotRecognizeSelector:] + 232
4 CoreFoundation 0x0000000116f389f8 ___forwarding___ + 1280
5 CoreFoundation 0x0000000116f3ad1c _CF_forwarding_prep_0 + 92
6 Intercom 0x000000010bbb424c IntercomSDK_saveViewHierarchy + 474756
7 Intercom 0x000000010bbb41c8 IntercomSDK_saveViewHierarchy + 474624
8 Intercom 0x000000010bbb0fac IntercomSDK_saveViewHierarchy + 461796
9 Intercom 0x000000010bbb0f28 IntercomSDK_saveViewHierarchy + 461664
10 Intercom 0x000000010bb936dc IntercomSDK_saveViewHierarchy + 340756
11 Intercom 0x000000010bb93650 IntercomSDK_saveViewHierarchy + 340616
12 CoreFoundation 0x0000000116e6503c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 140
13 CoreFoundation 0x0000000116e64f60 ___CFXRegistrationPost_block_invoke + 84
14 CoreFoundation 0x0000000116e64450 _CFXRegistrationPost + 404
15 CoreFoundation 0x0000000116e63e2c _CFXNotificationPost + 688
16 Foundation 0x00000001100fc0c0 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
17 UIKitCore 0x000000012cf7a08c -[_UISceneLifecycleMonitor willEnterForeground] + 240
18 UIKitCore 0x000000012cf7ab0c __111-[_UIWindowSceneFBSSceneLifecycleMonitor transitionToTargetState:fromState:withTransitionContext:preparations:]_block_invoke_5 - 120
19 UIKitCore 0x000000012d49279c _UIScenePerformActionsWithLifecycleActionMask + 96
20 UIKitCore 0x000000012cf7a9d0 __111-[_UIWindowSceneFBSSceneLifecycleMonitor transitionToTargetState:fromState:withTransitionContext:preparations:]_block_invoke_4 - 128
21 UIKitCore 0x000000012cf8b1dc ___UISceneLifecycleSettingsUpdateBlockWithCanvasAndTransitionContext_block_invoke_2 - 288
22 UIKitCore 0x000000012cf7a74c -[_UIWindowSceneFBSSceneLifecycleMonitor transitionToTargetState:fromState:withTransitionContext:preparations:] - 528
23 UIKitCore 0x000000012cf8af9c ___UISceneLifecycleSettingsUpdateBlockWithCanvasAndTransitionContext_block_invoke - 276
24 UIKitCore 0x000000012cf8c5d8 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_blo
25 UIKitCore 0x000000012d395170 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:] + 656
26 UIKitCore 0x000000012d4a8950 _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion - 196
27 UIKitCore 0x000000012cf8c304 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] - 288
28 UIKitCore 0x000000012cdee1c4 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.198 - 608
29 UIKitCore 0x000000012cdecf8c -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 232
30 UIKitCore 0x000000012cdede48 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 220
31 UIKitCore 0x000000012d3bca3c -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 308
32 FrontBoardServices 0x000000011c7953b8 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 560
33 FrontBoardServices 0x000000011c7be444 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 - 124
34 FrontBoardServices 0x000000011c7a0bb4 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
35 FrontBoardServices 0x000000011c7be390 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke - 312
36 libdispatch.dylib 0x000000011780d93c _dispatch_client_callout + 16
37 libdispatch.dylib 0x0000000117811534 _dispatch_block_invoke_direct + 392
38 FrontBoardServices 0x000000011c7dffa0 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
39 FrontBoardServices 0x000000011c7dfe7c -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 196
40 FrontBoardServices 0x000000011c7dffd4 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 24
41 CoreFoundation 0x0000000116e9569c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
42 CoreFoundation 0x0000000116e955e4 __CFRunLoopDoSource0 + 172
43 CoreFoundation 0x0000000116e94d54 __CFRunLoopDoSources0 + 232
44 CoreFoundation 0x0000000116e8f43c __CFRunLoopRun + 768
45 CoreFoundation 0x0000000116e8ed28 CFRunLoopRunSpecific + 572
46 GraphicsServices 0x000000011c2d7bc0 GSEventRunModal + 160
47 UIKitCore 0x000000012d8c3fdc -[UIApplication _run] + 868
48 UIKitCore 0x000000012d8c7c54 UIApplicationMain + 124
49 NugttahDev 0x000000010256f8d4 main + 64
50 dyld 0x000000010500d558 start_sim + 20
51 ??? 0x00000001050ee0e0 0x0 + 4379828448
52 ??? 0x5a1d800000000000 0x0 + 6493486975226478592
)
libc++abi: 因未捕获的NSException类型异常终止

问题根源

从调用栈可以明确,崩溃是由Intercom SDK的IntercomSDK_saveViewHierarchy方法触发的。该方法尝试获取当前Scene的windows属性,但CarPlay使用的CPTemplateApplicationScene是基于模板的场景类型,并没有普通iOS场景的UIWindow层级结构,因此无法响应windows选择器,导致崩溃。

解决方案

1. 升级Intercom SDK优先

检查Intercom官方是否已发布修复CarPlay场景兼容性问题的新版本,直接升级到最新稳定版,这是最简单的解决方案。

2. 针对CarPlay场景禁用Intercom相关功能

在SceneDelegate中区分场景类型,当检测到是CarPlay场景时,跳过Intercom的视图相关初始化:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard scene is UIWindowScene else {
        // 处理CarPlay场景,不初始化Intercom视图相关功能
        return
    }
    // 普通iOS场景正常初始化Intercom
    Intercom.start(withApiKey: "你的API_KEY", forAppId: "你的APP_ID")
    // 其他初始化逻辑...
}

3. 拦截Intercom的生命周期通知

如果无法升级SDK,可以移除Intercom对UIApplicationWillEnterForegroundNotification的监听,避免其在CarPlay场景触发时执行不兼容操作:

// 在CarPlay场景激活时执行
[[NSNotificationCenter defaultCenter] removeObserver:[Intercom class] 
                                                name:UIApplicationWillEnterForegroundNotification 
                                              object:nil];

// 在iOS主场景激活时恢复监听
[[NSNotificationCenter defaultCenter] addObserver:[Intercom class] 
                                           selector:@selector(对应处理方法) 
                                               name:UIApplicationWillEnterForegroundNotification 
                                             object:nil];

4. 临时禁用Intercom视图功能

在CarPlay会话期间,调用Intercom的API禁用视图相关功能:

[Intercom setLauncherVisible:NO];

内容的提问来源于stack exchange,提问作者Usama Fouad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 18:02:02