0

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
            }
        }
    }
}

Example screenshot

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.

Ramon
  • 1,415
  • 9
  • 18

2 Answers2

0

I can confirm this issue is now magically resolved in the latest beta software. (iOS 16 beta 1)

No extra code added or changed.

Ramon
  • 1,415
  • 9
  • 18
  • 1
    How did you manage to display SwiftUI view on CarPlay ? – Ptit Xav Jul 08 '22 at 19:25
  • The same code as displayed above. This now works. Simply put the code in and make sure you set up the Info.plist as described. This way, your app knows it has a CarPlay screen. Use a `UIHostingController` and submit your SwiftUI view to it as root. – Ramon Jul 11 '22 at 10:07
0

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

Igro182
  • 17
  • 7
  • 1
    This was simply a test to see if SwiftUI would work in CarPlay. The app is supposed to be a navigation app, where the centered label in my screenshot is replaced with a map. The app was approved for beta testing (at the time; iOS 14), but I had removed all the clutter in the project (e.g. map) with iOS 15 and changed the project to simply update a label to debug. Did not work as the label was static (no change), but iOS 16 magically updates the SwiftUI label again, counting up the seconds elapsed. – Ramon Jul 18 '22 at 09:43