I'm trying to understand what is the best way to fetch data from the internet and display it in the Widget.
I also added .onBackgroundURLSessionEvents to my WidgetConfiguration. When I run the app I get following error:
Code Block swift func timeline(with context: Context, completion: @escaping (Timeline<SampleEntry>) -> ()) { let currentDate = Date() let entry = ... let timeline = Timeline(entries: [entry], policy: .never) let urlSession: URLSession = { let config = URLSessionConfiguration.background(withIdentifier: "MySession") return URLSession(configuration: config, delegate: URLSessionDel(), delegateQueue: nil) }() let backgroundTask = urlSession.downloadTask(with: URL(string: "https://example.com")!) backgroundTask.resume() completion(timeline) }
I also added .onBackgroundURLSessionEvents to my WidgetConfiguration. When I run the app I get following error:
I watched the session but don't think it was explained well. Additionally I would like to know why in the example from the session there is no occurance of background session? They use mock API and just call completion inside the closure (in func timeline...)BackgroundSession <3A34B7CB-DD73-482F-9F08-8916F11D9624> connection to background transfer daemon invalidated