Instance Method

initWithAuthenticationChallenge:sender:

Creates an authentication challenge from an existing challenge instance.

Declaration

- (instancetype)initWithAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge sender:(id<NSURLAuthenticationChallengeSender>)sender;

Parameters

challenge

The challenge that you want to copy. Usually, this is a challenge received by an existing NSURLProtocol 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 NSURLProtocol subclass that called this method.

Return Value

A new authentication challenge object, based on an existing challenge.

Discussion

Most apps don’t create NSURLAuthenticationChallenge instances themselves. Instead, they handle received challenges in the URLSession:task:didReceiveChallenge:completionHandler: method of NSURLSessionTaskDelegate.

However, you might need to create authentication challenge objects when adding support for custom networking protocols, as part of a custom NSURLProtocol subclass. When you subclass an existing NSURLProtocol subclass, this initializer lets you modify challenges issued by the existing class so that your subclass receives any responses to those challenges.

See Also

Creating an Authentication Challenge Instance

initWithProtectionSpace:proposedCredential:previousFailureCount:failureResponse:error:sender:

Initializes an authentication challenge from parameters you provide.