I'm creating a widget for my application and successfully added intent configuration with dynamic data that I got from API.
This snippet gets the list and returns it to Intent:
func provideLeagueOptionsCollection(for intent: LeagueConfigurationIntent,
with completion: @escaping (INObjectCollection<LeagueType>?, Error?) -> Void) {
request(for: Leagues.self, completion: { leagueList in
let leagues = leagueList as! Leagues
let activeLeagues = leagues.leagueList.map { (league: League) -> LeagueType in
LeagueType(identifier: league.id,
display: league.name)
}
let collection = INObjectCollection(items: activeLeagues)
completion(collection, nil)
})
}
What I want to add is, when the user selects anything from this list, I want to show another option to select, it goes something like that:
- User selects League.
- Intent fetches Teams data from API with League's
id
provided on selection before and team list selection gets visible. - User selects a team from the second list.
- Intent returns this data to
IntentTimelineProvider
->getTimeline()
- The widget shows the selected team's stats.
I tried to debug step-by-step, but after the first selection, none of these ConfigurationIntentHandling
functions gets called.
func provideTeamOptionsCollection(for intent: TeamConfigurationIntent, with completion: @escaping (INObjectCollection<TeamType>?, Error?) -> Void) { ... }
func provideLeagueOptionsCollection(for intent: LeagueConfigurationIntent,
with completion: @escaping (INObjectCollection<LeagueType>?, Error?) -> Void) { ... }
// This method only gets called when interacted with League opiton in configuration view (not after selection from data list).
override func handler(for intent: INIntent) -> Any { return self }
// This method only gets called when the configuration menu shows up.
My goal is to filter teams from a selected league, so the user won't have to scroll through a long list of teams.
Also open for another suggestions beside this approach.