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

发布于 2025-01-15 14:38:18 字数 1508 浏览 2 评论 0原文

随着 iOS 15.4(2022 年 3 月 14 日)的更新,CarPlay 应用程序中的状态更新 (SwiftUI) 似乎已被破坏。

我已将代码简化为下面的示例。请注意,这在 iOS+CarPlay 15.3 中有效。这也适用于运行 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
            }
        }
    }
}

示例屏幕截图

我可以得出结论,SwiftUI CarPlay 应用程序中的状态未更新。有没有新的状态更新方法?我似乎无法指出我可能错过的任何事情。也许 SwiftUI 尚未完全支持 CarPlay 集成。 我还修改了代码以使用顶部的菜单按钮来增加 self.test。这也没有任何效果。

配置信息

CarPlay 应用程序是使用 Info.plist 设置的。

Application Scene Manifest
> Scene Configuration
>> CPTemplateApplicationSceneSessionRoleApplication (Array)
>>> Item 0
>>>> UISceneDelegateClassName = $(PRODUCT_MODULE_NAME).AppDelegate
>>>> UISceneConfigurationName = Default Configuration

我在 AppDelegate 中监听 CPTemplateApplicationSceneDelegate 并相应地提交适当的模板。然后,我将 UIHostingController 绑定到 CPWindowrootViewController 属性。

我很想了解一些导致这种状态更新不足的原因。不知道我在这里缺少什么。非常感谢您的努力和回应。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白龙吟 2025-01-22 14:38:18

我可以确认这个问题现在已经在最新的测试版软件中神奇地解决了。 (iOS 16 beta 1)

没有添加或更改额外的代码。

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

No extra code added or changed.

风蛊 2025-01-22 14:38:18

您是否已在 CarPlay 中使用 SwiftUI 提交应用程序以供审核?获得批准了吗?

根据 Apple 文档,您应该仅使用应用程序权利允许的模板: CarPlay 编程指南

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文