In C, the definition of NULL is 0, and in Objective-C, NO is smoothed to FALSE, which is smoothed to 0, so basically returning NULL is the same as returning NO.
The problem is that according to the documentation:
This method is called before any authentication attempt is made.
If you return NO, the connection will not ask for credentials to automatically store and do not store credentials. However, in your connection: didReceiveAuthenticationChallenge: method, you can consult the credential store yourself and save the credentials yourself, as needed.
Not using this method is the same as returning YES .
Instead of returning NULL, return YES according to the default implementation
EDIT: NO has an alias (BOOL)0 , not false , which is a true boolean type
In particular, the definition of YES / NO is in objc.h
typedef signed char BOOL; // BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C" // even if -funsigned-char is used.
EDIT: As pointed out in the comments below, @ AminNegm-Awad mine is just a (possibly more) simplification of the NULL value, since 0 is how it is finally evaluated, but it is not its real value.
#ifdef __cplusplus #ifdef __GNUG__ #define __DARWIN_NULL __null #else #ifdef __LP64__ #define __DARWIN_NULL (0L) #else #define __DARWIN_NULL 0 #endif #endif #else #define __DARWIN_NULL ((void *)0) #endif
In fact, by looking at <sys/_types.h> , you can find out that __DARWIN_NULL for Objective-C code is evaluated as ((void *)0) (checked by writing __DARWIN_NULL to xcode and cmd + by clicking it), thus from @ Comment by AminNegm-Awad:
An integer constant expression with a value of 0 or such a cast to type void * expression is called a null pointer constant. 55) If the null value is a pointer constant converted to a pointer type, as a result, a pointer called a null pointer is guaranteed to compare unevenly with a pointer to any object or function ". As an integral, it is 0 (null is a pointer constant). If it is a pointer, then it is a pointer other than 0.
In a C ++ application, instead of __DARWIN_NULL , __null , an internal compiler, is computed.
BACK TO QUESTION:
The mediation delegate method seems clean to me, especially if you want to hide some of the NSURLConnectionDelegate methods. This approach is more or less the same for methods -(void) , the difference is that you do not need to return anything, but simply call the delegated method. Now I cannot provide you with a complete example, but tonight I will send something