WidgetKit getCurrentConfigurations returns wrong list of widget-configurations

Viewed 1428

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

3 Answers

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.

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.

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?

Related