I've used NSURLConnection
a thousand times. This one is not sending the request, or calling the delegate callbacks. If I set the delegate to nil, the request does go out over the wire. No callbacks, of course. If I set the delegate to some other random object in my project that happens to conform to NSURLConnectionDelegate
, then the callbacks work.
Why would NSURLConnection
fail for a specific delegate instance?
This has been confirmed to be on the main thread, the main run loop and the problematic object answers YES
to conformsToProtocol:
for the appropriate protocols. It's a singleton and the breakpoint in dealloc is never hit.
Adding code here. It's nothing out of the ordinary nor does it add anything beyond what I said. self is the correct object that fails; Toolbar... is the random one that gets callbacks.
mSessionCookieConnection = [ NSURLConnection connectionWithRequest: cookieReq
delegate: self ];///[ ToolBarHeaderViewController sharedToolBarHeaderViewController ] ];
NSLog( @"Conforms to protocols: %d %d", [ self.class conformsToProtocol: @protocol( NSURLConnectionDataDelegate ) ],
[ self.class conformsToProtocol: @protocol( NSURLConnectionDelegate ) ] );
NSLog( @"Is main thread %@", ([NSThread isMainThread] ? @"Yes" : @" NOT" ));
NSLog( @"%@ the main run loop.", [[ NSRunLoop currentRunLoop ] isEqual: [ NSRunLoop mainRunLoop ]] ? @"Using" : @"Not using" );
The output is:
2015-05-07 08:10:50.201 ZZZ[5889:11316419] Conforms to protocols: 1 1
2015-05-07 08:10:50.201 ZZZ[5889:11316419] Is main thread Yes
2015-05-07 08:10:50.202 ZZZ[5889:11316419] Using the main run loop.