Widget getTimeline method called multiple times for customized intents

Viewed 1713

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 on each refresh - including previously-selected ones.

I would expect getTimeline to only be called with the currently-selected intent. 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 sample code and added a print statement to the getTimeline method. I then:

  1. Run the app and open it once.
  2. Add a widget to the home screen.
  3. Run the widget extension target on the simulator.
  4. Select the character Egghead.
  5. Select the character Cake.

This is what prints on the next widget refresh (usually ~15 mins):

- Timeline: nil
- Timeline: Optional("Egghead")
- Timeline: Optional("Cake")

Any help is much appreciated, thanks!

0 Answers
Related