I had a problem from which didReceiveData and didCompleteWithError are not being called. Here is my code:
class LoginViewController: UIViewController, NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate { . . . }
@IBAction func loginAction(sender: AnyObject) { var sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration() var session = NSURLSession(configuration: sessionConfiguration, delegate: self, delegateQueue:nil) let postParams = "email="+" rabcd@gmail.com &password="+"abcd" let url = NSURL(string:"http://myurl.com/api/v1/user/login") let request = NSMutableURLRequest(URL: url!) request.HTTPMethod = "POST" request.HTTPBody = postParams.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) let task = session.dataTaskWithRequest(request) task.resume() }
These are the delegates that I implemented
func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveResponse response: NSURLResponse, completionHandler: (NSURLSessionResponseDisposition) -> Void) { } func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveData data: NSData) { } func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) { }
Here I looked with break points
didReceiveResponse is called, but the other two are not called.
Please, help!
source share