session.dataTaskWithURL completionHandler never called

后端 未结 1 688
执念已碎
执念已碎 2020-12-19 10:30

I have the following code :

let urlPath:String = apiURL + apiVersion + url + \"?api_key=\" + apiKey
let url = NSURL(string: urlPath)
let session = NSURLSessi         


        
相关标签:
1条回答
  • 2020-12-19 10:54

    The task never completes because it never gets started. You have to manually start the data task using its resume() method.

    let urlPath = apiURL + apiVersion + url + "?api_key=" + apiKey
    let url = NSURL(string: urlPath)!
    let session = NSURLSession.sharedSession()
    
    let task = session.dataTaskWithURL(url) { data, response, error in
        print("Task completed")
        // rest of the function...
    }
    
    task.resume()
    
    0 讨论(0)
提交回复
热议问题