My program is shown in following.
I want to get the dataTask session's error code working in background, but I haven't achieved it.
let config:URLSessionConfiguration = URLSessionConfiguration.background(withIdentifier: "abcd")
self.session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
let task: URLSessionDataTask = session!.dataTask(with: myRequest as URLRequest)
task.resume()
In the program above, there isn't any parameter with error information, so I rewrite it as following.
But when I run the following program, the exception error happens.
By the way, about the following program, it can be run successfully when URLSession is configured as normal session, but when URLSession is configured as background session as following, the exception error happens when it's run.
Anyone can give me some advice?
Thanks a lot!
let config:URLSessionConfiguration = URLSessionConfiguration.background(withIdentifier: "abcd")
self.session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
let task: URLSessionDataTask = session!.dataTask(with: myRequest as URLRequest) { (data, response, error) in
if let response = response as? HTTPURLResponse {
NSLog("response.statusCode = \(response.statusCode)")
}
}
task.resume()