如何用SwiftUI Previewer预览LiveActivity?预览报错排查
Live Activity预览报错「Cannot preview this file」求助
根据WWDC 24的内容,所有Live Activity的UI都可通过Previewer可视化,但我目前遇到了「Cannot preview this file」的错误。
我的代码如下:
struct LiveActivityTest: Widget { var body: some WidgetConfiguration { ActivityConfiguration(for: CustomLAData.self, content: {context in VStack{ Image(systemName: "globe") .resizable() Text("Text 1") } }, dynamicIsland: {context in let timeRange = Date()...Date.now+100 return DynamicIsland{ DynamicIslandExpandedRegion(.leading, content: { Text("Text 1") .bold() }) DynamicIslandExpandedRegion(.trailing, content: { Text(timerInterval: timeRange, pauseTime: timeRange.lowerBound, countsDown: true) .font(.system(size: 22,weight: .bold)) .multilineTextAlignment(.trailing) }) DynamicIslandExpandedRegion(.bottom){ Text("Bottom Text") } } compactLeading: { Text("Compact leading") } compactTrailing: { Image(systemName:"globe") } minimal: { Image(systemName:"globe") } }) } } #Preview(as: .dynamicIsland(.compact), using: CustomLAData(), widget: { LiveActivityTest() }, contentStates: { CustomLAData.State() CustomLAData.State(isLoading:true) }) struct CustomLAData : ActivityAttributes{ typealias ContentState = State struct State : Codable,Hashable{ var isLoading = false } }
我尝试过不同的预览宏,但仍未定位到问题。
注:我已将Live Activity Widget添加至Widget Bundle,目标成员设置截图显示:该Widget对应的主App和Widget Extension选项均已勾选。
内容的提问来源于stack exchange,提问作者iroh
相关产品推荐
相关产品推荐

