Post

Replies

Boosts

Views

Activity

Reply to Deduplicated URLRequests
Thank you for your response @eskimo! Just so I understand you correctly: Is it possible to achieve request deduplication using two URLSession instances? If not, I guess the withTaskCancellationHandler was also part of the over simplification? So we should instead launch a data task and have the delegate "catch" the cancel error and retry it as a download task? You mentioned "cancel that and retry it as a download task". Are we responsible for canceling the tasks when the app transitions to the background, or can we rely on the system doing that? All the best, Jonas
Topic: App & System Services SubTopic: General Tags:
Dec ’22
Reply to Deduplicated URLRequests
I too would like more detail on this as it sounds like a great feature! But, I can't get the code snippet shown at 11:26 in the video Efficiency awaits: Background tasks in SwiftUI to work? Running this: let config = URLSessionConfiguration.background(withIdentifier: "isStormy")     config.sessionSendsLaunchEvents = true     let session = URLSession(configuration: config)           let response = await withTaskCancellationHandler {       try? await session.data(for: request)     } onCancel: {       let task = session.downloadTask(with: request)       task.resume()     } the line try? await session.data(for: request) throws the following exception: Completion handler blocks are not supported in background sessions. Use a delegate instead. Using Xcode 14.1 and a iOS 16.1 simulator. Creating the session with a delegate (like let session = URLSession(configuration: config, delegate: self, delegateQueue: nil)) doesn't help, same exception. Has anyone got this to work?
Topic: App & System Services SubTopic: General Tags:
Dec ’22