5

I've added Widget Extension with Configuration Intent. For the logging purposes, I've tried to log number of widgets user of the app has

 WidgetCenter.shared.getCurrentConfigurations { results in
     guard let widgets = try? results.get() else { return }
     ..<log widgets.count>...
 }

To my surprise, instead of the active [WidgetInfo]'s I've got a whole list of all the configuration intents ever been used in all the widgets instead of the actual ones.

I.e. I have 2 widgets on the screen, while WidgetCenter claims I have 9 current configurations. Any better ideas how to count widgets?

enter image description here

iOS 14 Beta 8 (both iPhone & Simulator) & Xcode 12 Beta 6

Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95

3 Answers3

4

Apparently iOS caches the configuration of all widgets ever created for an app, and recreates the configurations cache on startup of iOS.

So if you really want function getCurrentConfigurations to return the current configurations, restart your device first.

Ely
  • 8,259
  • 1
  • 54
  • 67
1

It seems to be an Beta-issue, that has been resolved with GA-release. Need to observe more, but with today's Xcode build I'm seeing relevant numbers.

Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95
  • Hey, I m trying to get all the widgets which are added to anywhere on the screen, but this method is giving me all the widgets what we are supporting. Is that the way it should work? I thought that this method will only give back information about the active widgets. – Magyar Miklós Sep 21 '20 at 14:55
  • 1
    Looks like I had to restart my device to make it works. – Magyar Miklós Sep 22 '20 at 10:06
0

We were also trying to do something similar and were experiencing a similar issue. I think the issue is that the device is holding on to every widget configuration ever installed (which is odd and IMO not helpful). Once I erased all contents and settings the widget info reset back to 0.

Perhaps just a restart would clear that info out?

Scott Wood
  • 364
  • 5
  • 11