I'm trying to upload large files in a background URLSession to a server that accepts HTTP/3 requests. Per its design, the server uses a self-signed SSL certificate.
In my testing, I can create a regular URLSession (foreground) with the following:
var request = URLRequest(url: dst, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 6.0)
request.assumesHTTP3Capable = true
request.httpMethod = "POST"
self.session.dataTask(with: request) {
<snip>
}
And handles the SSL certificate challenge by implementing the following for the delegate:
func urlSession(
_ session: URLSession,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping @Sendable (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
)
This approach works and I can communicate with the server. But when I try to apply the same for a background session for an upload task, the task seems to be stuck, i.e. never started by the system.
More specifically, the background session upload task works with iOS simulator. But on a real device connected to macOS, the task never started, and none of the delegate methods are called. The http/3 server didn't receive any request either.
The background session was created:
let appBundleName = Bundle.main.bundleURL.lastPathComponent.lowercased().replacingOccurrences(of: " ", with: ".")
let sessionIdentifier: String = "com.networking.\(appBundleName)"
let config = URLSessionConfiguration.background(withIdentifier: sessionIdentifier)
self.session = URLSession(configuration: config, delegate: self, delegateQueue: nil)
later, an upload task was created :
var request = URLRequest(url: dst, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 6.0)
request.assumesHTTP3Capable = true
request.httpMethod = "POST"
let backgroundTask = self.session.uploadTask(with: request, fromFile: src)
backgroundTask.resume()
My question(s): why is the background session upload task stuck? Is there a way to find out where it is stuck?
Does a background URLSession support app's delegate handling SSL certificate challenge?
The test env:
Xcode 14.2
macOS 12.6.7
iOS 15.7.7
Thanks!