Thank you for the solution, and it almost works perfectly! However, I am trying to wait for two network requests, and only the first one is running. Here is a sample of my code:
let waitForMyNetworkRequest = DispatchGroup()
waitForMyNetworkRequest.enter()
Task {
// This request successfully hits my server
await pushScoreUpdate()
// These log statements and requests don't run
logger.log("Successfully pushed score update")
await pushHistory(since: since)
logger.log("Successfully pushed history")
waitForMyNetworkRequest.leave()
}
// Force the system to wait for your network request.
waitForMyNetworkRequest.wait(timeout: .now() + 60.0)
Also, I'm not even able to read the response from my first request, even though I've confirmed that it hits my server. Here's a sample of my networking code:
...
let configuration = URLSessionConfiguration.default
configuration.sharedContainerIdentifier = "group.core.data.Present"
configuration.isDiscretionary = false
let (data, _) = try await URLSession(configuration: configuration).data(for: request)
logger.log("Got response")
...
Maybe I'm not setting up the DispatchGroup right to wait for multiple async functions? Or maybe it's the way I'm configuring my URLSession that automatically exits the dispatch group? It appears that I've made progress in being able to send the initial request, but the extension is still terminating before I'm able to read the response.