简体   繁体   English

iOS 15.4 - SwiftUI + CarPlay - 状态未更新

[英]iOS 15.4 - SwiftUI + CarPlay - State not updating

It seems that with the update of iOS 15.4 (March 14th, 2022) the state updating (SwiftUI) in a CarPlay app has been broken.随着iOS 15.4 (2022 年 3 月 14 日)的更新,CarPlay 应用程序中的状态更新 (SwiftUI) 似乎已被破坏。

I have simplified my code to the example below.我已将代码简化为下面的示例。 Please note this was working in iOS+CarPlay 15.3.请注意,这适用iOS+CarPlay 15.3。 This also works on an iOS (only) app running 15.4.这也适用于运行 15.4 的iOS(仅限)应用程序

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.我可以得出结论,SwiftUI CarPlay 应用程序中的状态未更新。 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.也许使用 SwiftUI 还没有完全支持 CarPlay 集成。 I had also reworked the code to use the menu button on top to increment self.test .我还修改了代码以使用顶部的菜单按钮来增加self.test This also does not have any effect.这也没有任何影响。

Configuration info配置信息

CarPlay app is set up using the Info.plist. CarPlay 应用程序是使用 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.我在AppDelegate中侦听CPTemplateApplicationSceneDelegate并相应地提交适当的模板。 I then bind a UIHostingController to the CPWindow 's rootViewController property.然后我将UIHostingController绑定到CPWindowrootViewController属性。

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.非常感谢您的努力和回应。

I can confirm this issue is now magically resolved in the latest beta software.我可以确认这个问题现在在最新的测试版软件中得到了神奇的解决。 (iOS 16 beta 1) (iOS 16 测试版 1)

No extra code added or changed.没有添加或更改额外的代码。

Have you submitted the app for review with SwiftUI in CarPlay?您是否已在 CarPlay 中使用 SwiftUI 提交应用以供审核? was it approved?被批准了吗?

As per Apple documentation you are supposed to use only templates allowed by your app entitlement: CarPlay programming Guide根据 Apple 文档,您应该只使用应用程序授权允许的模板: CarPlay 编程指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM