It seems that with the update of iOS 15.4 (March 14th, 2022) the state updating (SwiftUI) in a CarPlay app has been broken.
I have simplified my code to the example below. Please note this was working in iOS+CarPlay 15.3. This also works on an iOS (only) app running 15.4.
struct ContentView: View {
@State private var test: Int = 0
var body: some View {
VStack {
Text("Seconds elapsed: (self.test)")
}
.onAppear {
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
self.test += 1
}
}
}
}
I can conclude that the state is not updated in a SwiftUI CarPlay app. Is there any new way of updating the state? I can’t seem to pinpoint anything I might have missed. Maybe the CarPlay integration simply isn’t fully supported yet using SwiftUI.
I had also reworked the code to use the menu button on top to increment self.test
. This also does not have any effect.
Configuration info
CarPlay app is set up using the Info.plist.
Application Scene Manifest
> Scene Configuration
>> CPTemplateApplicationSceneSessionRoleApplication (Array)
>>> Item 0
>>>> UISceneDelegateClassName = $(PRODUCT_MODULE_NAME).AppDelegate
>>>> UISceneConfigurationName = Default Configuration
I listen for CPTemplateApplicationSceneDelegate
in my AppDelegate
and submit the appropriate template accordingly. I then bind a UIHostingController
to the CPWindow
‘s rootViewController
property.
I’d love to have some insights in what can cause this lack of updating the state. Not sure what I’m missing here. Thank you so much for your effort and response.
2
Answers
I can confirm this issue is now magically resolved in the latest beta software. (iOS 16 beta 1)
No extra code added or changed.
Have you submitted the app for review with SwiftUI in CarPlay? was it approved?
As per Apple documentation you are supposed to use only templates allowed by your app entitlement: CarPlay programming Guide