iOS 15.4 - SwiftUI + CarPlay - 状态未更新
随着 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
绑定到 CPWindow
的 rootViewController
属性。
我很想了解一些导致这种状态更新不足的原因。不知道我在这里缺少什么。非常感谢您的努力和回应。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以确认这个问题现在已经在最新的测试版软件中神奇地解决了。 (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.
您是否已在 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