var session = NSURLSession.sharedSession()
session.dataTaskWithRequest(urlRequest, 
                            completionHandler: {(data: NSData!, 
                                                 response: NSURLResponse!,                       
                                                 error: NSError!) in
                                                      println(data)
                                                      println(response)
                                                      println(error)
                                               })
So I am making this request, and the completion block is never called.
What's wrong?
Also I tried a synchronous and asynchronous form of the same request with NSURLConnection and it worked perfectly.
EDIT:
I tried assigning a dataTask variable to the session.dataTaskWithRequest and displayed it right after. It says this <__NSCFLocalDataTask: 0xb41bda0> { suspended } Suspended? Why?
So I tried calling it like this
session.dataTaskWithRequest(urlRequest, 
                        completionHandler: {(data: NSData!, 
                                             response: NSURLResponse!,                       
                                             error: NSError!) in
                                                  print(data)
                                                  print(response)
                                                  print(error)
                                           }).resume()
And it worked.
Seems like I have to call resume() on a default suspended session task.
Are you using playgrounds??
If you are, you should be careful to include:
 XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
In order to make the playground wait for the callback
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With