Hi,
I've followed lots of solutions on stackoverflow, tutorials and even the apple documentation but I can't figure out why my URLSession delegates methods are not called
Here is the code I use :
public class RestRequestor : NSObject, URLSessionTaskDelegate {
var receivedData: Data?
// private var session : URLSession?
private lazy var session: URLSession = {
let configuration = URLSessionConfiguration.default
configuration.waitsForConnectivity = true
return URLSession(configuration: configuration,
delegate: self, delegateQueue: nil)
}()
public func startLoad() {
let url = URL(string: "http://www.lefigaro.fr")!
receivedData = Data()
let task = session.dataTask(with: url)
task.resume()
}
func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask) {
print("On attend quelque chose")
}
func urlSession(_ session: URLSession, didBecomeInvalidWithError error: Error?) {
print("Là il y a comme un problème")
}
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
print("on a reçu quelque chose")
}
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
print("Ouf c'est fini")
}
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
print("on commence a recevoir quelquechose")
completionHandler(.allow)
}
}
and then I call
@IBActionfunc runthisone(_ sender:Any){
let titi = RestRequestor.init()
titi.startLoad()
}
I'm struggling with this one for 2 days without knowing what to do
Does anyone have an idea ?