Does anyone know how to implement CarPlay within SwiftUI LifeCycle? I always get an error when tried to open in CarPlay.
Application does not implement CarPlay template application lifecycle methods in its scene delegate.
Implementation worsk only when I move
@main
struct MyApp: App {
...
}
to
@main
final class AppDelegate: UIResponder, ObservableObject, UIApplicationDelegate {
...
}
This is not even triggered when I open app in CarPlay from AppDelegate
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
if let shortcutItem = options.shortcutItem {
AppDelegate.shortcutItem = shortcutItem
}
if(connectingSceneSession.role == UISceneSession.Role.carTemplateApplication) {
// CarPlay Scene
let sceneConfig = UISceneConfiguration(name: "CarPlay", sessionRole: connectingSceneSession.role)
sceneConfig.delegateClass = CarPlaySceneDelegate.self
return sceneConfig
} else {
// iPhone Scene
let sceneConfig = UISceneConfiguration(name: "Phone", sessionRole: connectingSceneSession.role)
sceneConfig.delegateClass = SceneDelegate.self
return sceneConfig
}
}