Post

Replies

Boosts

Views

Activity

Reply to Timeline refresh issue for widget on ios 18.2
By the way, code like the following. It runs directly, and it does work on iOS18.2. But not if it's a timeline refresh triggered by Button or Toggle. 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: .F2) entries.append(entry) let entry2 = Entry(date: currentDate.adding(.second, value: 3), type: .F1) entries.append(entry2) return .init(entries: entries, policy: .never) }
1w
Reply to Timeline refresh issue for widget on ios 18.2
Thank you very much for your reply. I think the default is F1. The func timeline function does not enter the criteria for if FriendGlobalType.type ==.f2, so there is only one entry. Every time I click the Button, the state changes to F2. At this point, the func timeline will generate two entries. One is F2. The other is the status change to F1 after 3 seconds. The init method and FriendGlobalType are for logging state. Because my request here is to trigger the network request after clicking Button on F1, await the network request, refresh the UI to F2. And then back to F1 in three seconds. I simplified the code and did not attach the network request code. This logic actually works on iOS17. But I don't know why ios 18.2 doesn't work. Is there a better design?
1w
Reply to Timeline refresh issue for widget on ios 18.2
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) }
1w
Reply to Timeline refresh issue for widget on ios 18.2
var isAudibleArming = false struct SoundAlarmIntent: AppIntent { static var title: LocalizedStringResource = "SoundAlarmIntent" func perform() async throws -> some IntentResult { isAudibleArming = true return .result() } } func timeline( for configuration: DynamicIntentWidgetPersonIntent, in context: Context ) async -> Timeline<Entry> { var entries: [Entry] = [] let currentDate = Date() let entry = Entry(person: person(for: configuration)) entries.append(entry) if isAudibleArming { let entry2 = Entry(person: Person(name: "Friend4", dateOfBirth: currentDate.adding(.second, value: 6))) entries.append(entry2) } return .init(entries: entries, policy: .never) } Maybe it's clearer this way。Can you help me? Thank you
2w