iOS SwiftUI CarPlay“Hello World”

iszxjhcz  于 2023-05-19  发布在  iOS
关注(0)|答案(1)|浏览(177)

我有一个完整的SwiftUI项目/应用程序(在AppStore中),我想添加一些CarPlay功能。我有权利正确设置,并能够看到图标上的CarPlay模拟器。
我已经尝试了各种info.plist配置与各种类配置,只有实现崩溃的时刻,当启动应用程序在模拟器中。
我对显示视图的方法有点困惑。我想从一个简单的“Hello world”开始,但即使这样也很有挑战性:)
这个问题似乎是我需要的,但没有涉及AppDelegate配置的足够细节。
iOS 15.4 - SwiftUI + CarPlay - State not updating
这看起来很有希望,但对我来说还不够详细:
https://dev.to/nitricware/adding-carplay-to-a-swiftui-life-cycle-app-h9h
这也是,但我怀疑这是一种旧的显示视图的方式。
https://www.adapptor.com.au/blog/enhance-existing-apps-with-carplay
如果我能得到一个简单的“Hello World”的帮助,我将不胜感激!
来自info.plist

<key>UIApplicationSceneManifest</key>
        <dict>
            <key>UIApplicationSupportsMultipleScenes</key>
            <true/>
            <key>UISceneConfigurations</key>
            <dict>
                <key>CPTemplateApplicationSceneSessionRoleApplication</key>
                <array>
                    <dict>
                        <key>UISceneDelegateClassName</key>
                        <string>$(PRODUCT_MODULE_NAME).CarPlaySceneDelegate</string>
                    </dict>
                </array>
            </dict>
        </dict>

CarPlaySceneDelegate.swift

import Foundation
import CarPlay

class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
    
  func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,
                                  didConnect interfaceController: CPInterfaceController) {
    
    let screen = CPInformationTemplate(title: "Root", layout: .leading, items: [CPInformationItem(title: "Hello", detail: "CarPlay")], actions: [])
    
    interfaceController.setRootTemplate(screen, animated: true, completion: { _,_ in
        // Do nothing
    })
  }
}

谢谢

bqf10yzr

bqf10yzr1#

不知道它是否会改变什么,但你的字典在Indi.plist似乎不完整,试试这个:

<key>UISceneConfigurations</key>
<dict>
    <key>CPTemplateApplicationSceneSessionRoleApplication</key>
    <array>
        <dict>
            <key>UISceneClassName</key>
            <string>CPTemplateApplicationScene</string>
            <key>UISceneDelegateClassName</key>
            <string>$(PRODUCT_MODULE_NAME).CarPlaySceneDelegate</string>
            <key>UISceneConfigurationName</key>
            <string>CarPlay</string>
        </dict>
    </array>
</dict>

相关问题