init(authenticationChallenge:sender:)
Creates an authentication challenge from an existing challenge instance.
Declaration
init(authenticationChallenge challenge: URLAuthenticationChallenge, sender: any URLAuthenticationChallengeSender)Parameters
- challenge:
The challenge that you want to copy. Usually, this is a challenge received by an existing Urlprotocol subclass that you are subclassing.
- sender:
The sender that you want to use for the new object. Typically, the sender is the instance of your custom Urlprotocol subclass that called this method.
Return Value
A new authentication challenge object, based on an existing challenge.
Discussion
Most apps don’t create URLAuthenticationChallenge instances themselves. Instead, they handle received challenges in the urlSession(_:task:didReceive:completionHandler:) method of URLSessionTaskDelegate.
However, you might need to create authentication challenge objects when adding support for custom networking protocols, as part of a custom URLProtocol subclass. When you subclass an existing URLProtocol subclass, this initializer lets you modify challenges issued by the existing class so that your subclass receives any responses to those challenges.