I am using an UIKit
app and added a widget with SwiftUI
and Widgetkit
.
Now I want to update the widget when the user does something one the main app.
Normally I should use WidgetCenter.shared.reloadAllTimelines()
right?
But this only works with SwiftUI
.
I could say that my widget should reload every second. But my widget does a json request. That would also do the json request every second which I don't want.
For you information. The Main app shares UserDefaults
with the widget. Depending on the UserDefaults
it reads it and changes it appearance.
Right now the widget loads the correct UserDefault when it is added first. But as I said changing the added Widget doesn't work.
I guess removing and adding the widget is not an userfriendly option.
WidgetCenter.shared.reloadAllTimelines()
is independent from the UI framework you use. You can use it from SwiftUI or UIKit.
If you're worried about making too many requests you could call that method only once your app goes to the background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With