URLSessionDelegate Function Not Being Called

前端 未结 1 1515
独厮守ぢ
独厮守ぢ 2020-12-10 22:45

I would like to process data as it comes in, so I\'ve instiated a URL session like so:

let session = URLSession(configuration: sessionConfiguration, delegate         


        
相关标签:
1条回答
  • 2020-12-10 22:59

    The reason this is not working is that you're creating your data task with a completion handler. Instead you must use the dataTask(with:) function instead.

    I also missed this in the documentation and spent hours wondering why my delegate methods weren't being called.

    From the docs:

    By using the completion handler, the task bypasses calls to delegate methods for response and data delivery, and instead provides any resulting NSData, URLResponse, and NSError objects inside the completion handler. Delegate methods for handling authentication challenges, however, are still called.

    0 讨论(0)
提交回复
热议问题