Thank you for your reply, there is a problem with the previous code date. I've put up part of my project code, and my project has a lot of different views, so I use FriendType to differentiate, and I use a global FriendGlobalType to keep track of which FriendType I'm currently in. For simplicity's sake, I've only used two types so far. Question: Why does the view2 corresponding to F2 flash by on iOS18.2 and show view1 corresponding to F1 without a delay of 3 seconds? Everything works on iOS17.
struct Entry: TimelineEntry {
var date: Date = .now
var person: Person?
var type: FriendType = .F1
init(date: Date, person: Person? = nil, type: FriendType) {
self.date = date
self.person = person
self.type = type
FriendGlobalType.type = type
}
}
extension DynamicIntentWidget {
struct EntryView: View {
let entry: Entry
var body: some View {
VStack {
switch entry.type {
case .F1:
Button(intent: FriendIntent()) {
Text("Click")
}
case .F2:
Text("F2")
}
} .containerBackground(.clear, for: .widget)
}
}
}
enum FriendType: String, AppEnum {
case F1
case F2
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "FriendType")
static let caseDisplayRepresentations: [Self: DisplayRepresentation] = [
.F1: DisplayRepresentation(title: "F1"),
.F2: DisplayRepresentation(title: "F2"),
]
}
struct FriendGlobalType {
static var type: FriendType = .F1
}
struct FriendIntent: AppIntent {
static var title: LocalizedStringResource = "FriendIntent"
func perform() async throws -> some IntentResult {
FriendGlobalType.type = .F2
return .result()
}
}
func timeline(
for configuration: DynamicIntentWidgetPersonIntent,
in context: Context
) async -> Timeline<Entry> {
var entries: [Entry] = []
let currentDate = Date.now
let entry = Entry(date: currentDate,person: person(for: configuration),type: FriendGlobalType.type)
entries.append(entry)
if FriendGlobalType.type == .F2 {
let entry2 = Entry(date: currentDate.adding(.second, value: 3), type: .F1)
entries.append(entry2)
}
return .init(entries: entries, policy: .never)
}