用途:指导开发者使用 CarPlay 框架在车载屏幕上构建应用,采用系统模板化 UI,应用只提供内容,由系统负责渲染。目标环境为 Swift 6.3 / iOS 26+。
主要能力:覆盖权限与工程配置、场景配置、模板总览、导航应用、音频应用、通信应用、兴趣点应用、模拟器测试、常见错误与审查清单。
权限与配置:CarPlay 需 Apple 按类别授予专属 entitlement,需在 developer.apple.com/contact/carplay 申请并同意 CarPlay Entitlement Addendum。类别对应键包括 com.apple.developer.carplay-audio、carplay-communication、carplay-maps、carplay-charging、carplay-parking、carplay-quick-ordering。工程需更新 App ID、生成新描述文件、关闭自动签名并导入 CarPlay 描述文件、添加 Entitlements.plist 并设置 Code Signing Entitlements。
场景配置:在 Info.plist 声明 CarPlay 场景,实现 CPTemplateApplicationSceneDelegate。非导航应用只获得 CPInterfaceController;导航应用额外获得 CPWindow,用于绘制地图内容。
模板:通用模板含 CPTabBarTemplate、CPListTemplate、CPGridTemplate、CPInformationTemplate、CPAlertTemplate、CPActionSheetTemplate;类别专属模板含 CPMapTemplate、CPSearchTemplate、CPNowPlayingTemplate、CPPointOfInterestTemplate、CPContactTemplate。CPTabBarTemplate 只能作为根模板,不能 push 或 present。
导航:使用 com.apple.developer.carplay-maps,根模板须为 CPMapTemplate,通过 CPTrip、CPRouteChoice 展示行程预览,用 startNavigationSession 启动导航会话并更新 CPManeuver 与 CPTravelEstimates。
音频:使用 com.apple.developer.carplay-audio,CPNowPlayingTemplate 为共享单例,从 MPNowPlayingInfoCenter 读取元数据,支持 Siri 助手单元格。
通信:使用 com.apple.developer.carplay-communication,展示消息列表与联系人,支持 INStartCallIntent。
兴趣点:充电、停车、点餐使用 CPPointOfInterestTemplate 与 CPInformationTemplate 展示位置与详情。
测试:在 Xcode 模拟器选择 I/O > External Displays > CarPlay,默认 800x480 @2x,可用 defaults write com.apple.iphonesimulator CarPlayExtraOptions -bool YES 开启导航额外选项。模拟器无法测试锁屏、Siri、与车载收音机音频共存及物理输入硬件。
限制:需 Apple 授予权限;模板类型固定;须遵守车辆显示限制(limitedUserInterfaces、maximumItemCount、maximumSectionCount);CPListItem.handler 必须在所有路径调用 completion;CPWindow 仅用于地图内容。扩展模式见 references/carplay-patterns.md。