Instance Method


Initializes an authentication challenge from parameters you provide.


- (instancetype)initWithProtectionSpace:(NSURLProtectionSpace *)space proposedCredential:(NSURLCredential *)credential previousFailureCount:(NSInteger)previousFailureCount failureResponse:(NSURLResponse *)response error:(NSError *)error sender:(id<NSURLAuthenticationChallengeSender>)sender;



The protection space for the authentication challenge. This provides additional information about the authentication request, such as the host, port, authentication realm, and so on.


The proposed credential, or nil.


The total number of previous failures for this request, including failures for other protection spaces.


An instance of NSURLResponse containing the server response that caused you to generate an authentication challenge, or nil if no response object is applicable to the challenge.


An NSError instance describing the authentication failure, or nil if it is not applicable to the challenge.


The object that initiated the authentication challenge (typically, the object that called this method).

Return Value

A new authentication challenge object, with the given properties.


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 your custom NSURLProtocol subclasses.

See Also

Creating an Authentication Challenge Instance

- initWithAuthenticationChallenge:sender:

Creates an authentication challenge from an existing challenge instance.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software