SwiftUI lifecycle / CarPlay / data model

Is there a way to share a SwiftUI App's @Observable model into a CPTemplateApplicationSceneDelegate ?

Is there an incantation to go from the UIApplicationDelegate via @UIApplicationDelegateAdaptor to the UISceneDelegate for CarPlay via a userInfo? I can't seem to figure it out.

Otherwise I have to use a shared global, and I'd prefer not to have to do it this way. Any ideas? Thanks!

Hi, can you share more about what you are trying to do?

Your app may be launched for the first time in CarPlay, and only in CarPlay, so the CarPlay lifecycle needs to be kept independent from your app's on-device scenes. In other words, your app needs to work properly if it receives only a CarPlay scene, and no phone scene.

Hi. Basically I want the state of the iOS app to be shared with CarPlay, if the iOS app is already launched. I also want the CarPlay state to be shared with the iOS app if iOS is launched later. If there is no state to share, each will initialize its own state. Will CPTemplateApplicationSceneDelegate be "launched" w/o starting the iOS App / UIApplicationDelegate?

As an example, I see Apple Maps will share the selected route if you loaded it at home before getting in the car. On the iOS app, I see the Apple Maps steps UI if the CarPlay is navigating.

I think it boils down to wanting to know how to transfer data from a SwiftUI App to UISceneDelegate. I assumed it would be via the UIApplicationDelegate.

The CoastalRoads CarPlay example doesn't use SwiftUI, and it has TemplateManager.shared. I was hoping there would be a way to pass data around via the app and scene delegates w/o a .shared.

Thanks for replying!

SwiftUI lifecycle / CarPlay / data model
 
 
Q