1

When it comes to task-level authentication of a URLSession I see references to two different method signatures in Apple's documentation:

  • E.g. here is a reference to urlSession(_,task:,didReceive:, completionHandler:).
  • E.g. here is a reference to urlSession(_, task:,didReceiveChallenge:completionHandler).

Which is the right one (or do both apply under different circumstances)?

Intuitively one could think that the 1st one is a typo (mistake in documentation), and that the 2nd one applies. But a look into iOS header files suggests that the 1st one applies and the 2nd is a typo or obsolete.

So which exact method of a URLSessionDelegate will be called (in iOS 10) for delivering a (task-level) authentication challenge to an app? (I will go with the 1st one for the time being.)

Drux
  • 11,992
  • 13
  • 66
  • 116

1 Answers1

1

This is actually the same delegate method. You just got the Swift signature wrong in your second example. See the documentation for the method and switch between Swift and Objective-C. So the actual signature is indeed urlSession(_, task:, didReceive:, completionHandler:).

DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • Didn't get Apple the signature wrong in this case (See 2nd like to documentation)? Perhaps it is because this documentation is marked prerelease (from June 2016). – Drux Aug 30 '16 at 08:06
  • On further inspection: Maybe the signatures are slightly different between the Objective-C and Swift versions. I am interested in the Swift version for which the 1st sample indeed seems to apply. – Drux Aug 30 '16 at 08:12
  • Yes, the signatures do differ in Swift and Objective-C. No, it's not an error. In Objective-C, we need to specify _what_ was received to distinguish between several possibilities. In Swift, we [also have (reliable) type information to distinguish them](http://stackoverflow.com/questions/27690076/multiple-functions-with-the-same-name) so there's no need to put that (redundant) information in the method name. – DarkDust Aug 30 '16 at 08:16
  • Okay, got it now. Thx. – Drux Aug 30 '16 at 08:18