Detect app launch from WidgetKit widget extension

To detect an app launch from a WidgetKit widget extension where the parent application supports scenes you’ll need to implement scene(_:openURLContexts:), for launching from a background state, and scene(_:willConnectTo:options:), for launching from a cold state, in your parent application’s SceneDelegate. Also, add widgetURL(_:) to your widget’s view. Widget’s View: struct WidgetEntryView: View { var entry: … Read more

How to refresh Widget data?

You can’t use the ObservedObject like you’d normally use in your App. In Widgets you use a TimelineProvider which creates an Entry for your view. Add another property to your TimelineEntry, let’s call it clubName: struct SimpleEntry: TimelineEntry { let date: Date let clubName: String } Update the NetworkManager and return results in the completion: … Read more

Share data between main App and Widget in SwiftUI for iOS 14

You can add the AppGroup capability for both your Widget and App (here is a very good explanation how to add it). UserDefaults Instead of UserDefaults.standard just use the shared UserDefaults for your AppGroup: UserDefaults(suiteName: <your_app_group>) Then you can read/write data like explained in this answer. File Container With the AppGroup entitlement you get access … Read more