URLSession bytes API

I was testing bytes(from:delegate:) API from URLSession. I was testing the implementation of the delegate. I didn't get any callback to the delegate when I got 400 status code in the response(No token is provided). I have implemented other delegates also. Still I didn't get any callback in any of those functions. Please let me know if I am missing something here?

Accepted Reply

Right. When you use convenience methods like bytes(from:delegate:), certain delegate methods are skipped because the corresponding info is returned as the function result [1]. In this case, the function returns a URLResponse value holding the status code, so there’s no need to call urlSession(_:dataTask:didReceive:completionHandler:).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Or as a completion handler parameter, if you’re using the completion handler convenience methods.

Replies

Right. When you use convenience methods like bytes(from:delegate:), certain delegate methods are skipped because the corresponding info is returned as the function result [1]. In this case, the function returns a URLResponse value holding the status code, so there’s no need to call urlSession(_:dataTask:didReceive:completionHandler:).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Or as a completion handler parameter, if you’re using the completion handler convenience methods.