I am building a widget with configurable options (dynamic option) where the options are pull from api (ultimately the options are return from a server, but during my development, the response is constructed on the fly from locally).
Right now, I am able to display the widget and able to pull out the widget configuration screen where I can choose my config option . I am constantly having an issue where the loading the available options when selected a particular option (e.g. Category) and display them on the UI. Sometime, when I tap on the option "Category" and the loading indicator keeps spinning for while before it can populate the list of topics (return from methods in NewsCategoryQuery struct via fetchCategoriesFromAPI ). Notice that I already made my fetchCategoriesFromAPI call to return the result on the fly and however the widget configuration UI stills take a very long time to display the result. Even worst, the loading (loading indicator keep spinning) sometime will just kill itself after a while and my guess there are some time threshold where the widget extension or app intent is allow to run, not sure on this?
My questions:
- How can I improve the loading time to populate the dynamic options in widget configuration via App Intent
Here is my sample code for my current setup
struct NewsFeedConfigurationIntent: AppIntent, WidgetConfigurationIntent { static let title: LocalizedStringResource = "Configure News Topic Options" static let description = IntentDescription("Select a topic for your news.") @Parameter(title: "Category", default: nil) var category: NewsCategory? }
struct NewsCategory: AppEntity, Identifiable { let id: String let code: String let name: String static let typeDisplayRepresentation: TypeDisplayRepresentation = "News Topic" static let defaultQuery = NewsCategoryQuery() var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: LocalizedStringResource(stringLiteral: name)) } }
struct NewsCategoryQuery: EntityQuery { func entities(for identifiers: [NewsCategory.ID]) async throws -> [NewsCategory] { let categories = fetchCategoriesFromAPI() return categories.filter { identifiers.contains($0.id) } } func suggestedEntities() async throws -> [NewsCategory] { fetchCategoriesFromAPI() } }
func fetchCategoriesFromAPI() -> [NewsCategory] { let list = [ "TopicA", "TopicB", "TopicC", ....... ] return list.map { item in NewsCategory(id: item, code: item, name: item.capitalized) } }