Search code examples
swiftios14

Determine if app's iOS 14 widget is placed on the home screen - Swift


Is there a way to determine if and how many of your app's widgets are being used by the user?

I tried using

WidgetCenter.shared.getCurrentConfigurations { result in
    switch result {
        case let .success(info):
            let myWidgetCount = info.count
            print(myWidgetCount)
        case let .failure(error): print(error)
    }
}

but it's way off. It's giving me way more than it should.

Edit: it's including all of the ones I added and later removed as well. Is there a way to get only the ones that are currently placed on their home screen or the widget section?


Solution

  • It turns out this is an issue with the simulator. On a physical device, it does not include removed widgets.