In my iOS 14 widget with a single custom intent, when the user selects one intent, then changes to another, my getTimeline method is called multiple times for each intent per refresh - including previously-selected ones.
I would expect getTimeline to only be called with the currently-selected intent. Am I misunderstanding how widgets are designed?
Is there a way to check whether the intent is the currently-selected intent? I make a network request in the getTimeline method and I do not want to make multiple requests when the widget only shows one intent.
As an example, I downloaded the Emoji Ranger - https://developer.apple.com/documentation/widgetkit/building_widgets_using_widgetkit_and_swiftui sample code and added a print statement to the getTimeline method. I then:
Run the app and open it once.
Add a widget to the home screen.
Run the widget extension target on the simulator.
Select the character Egghead.
Select the character Cake.
This is what prints on the next widget refresh (usually ~15 mins):
Timeline: nil
Timeline: Optional("Egghead")
Timeline: Optional("Cake")
I noticed that sometimes it calls getTimeline with previous intents in an unexpected order (not old-recent). Any help is much appreciated, thanks!