Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WidgetKit getCurrentConfigurations returns wrong list of widget-configurations

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

like image 701
Konstantin Loginov Avatar asked Sep 14 '20 12:09

Konstantin Loginov


2 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.

like image 55
Ely Avatar answered Nov 18 '22 12:11

Ely


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.

like image 1
Konstantin Loginov Avatar answered Nov 18 '22 13:11

Konstantin Loginov