NSURLSession completion block not called

前端 未结 6 840
天命终不由人
天命终不由人 2021-02-18 19:07
var session = NSURLSession.sharedSession()
session.dataTaskWithRequest(urlRequest, 
                            completionHandler: {(data: NSData!, 
                             


        
6条回答
  •  一生所求
    2021-02-18 19:38

    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.

提交回复
热议问题