Some more info.  I am on Snow Leopard but get the same results on Leopard.
I took the code from NSURLConnection.SetDelegate() and moved it into my code
like this:

                Action<NSURLConnection.NSURLConnectionEventDispatcher>
assignment =
                (d =>
                    {
                        d.ConnectionDidCancelAuthenticationChallenge += new
NSURLConnection.ConnectionDidCancelAuthenticationChallengeEventHandler(d_ConnectionDidCancelAuthenticationChallenge);
                        d.ConnectionDidFailWithError += new
NSURLConnection.ConnectionDidFailWithErrorEventHandler(d_ConnectionDidFailWithError);
                        d.ConnectionDidFinishLoading += new
NSURLConnection.ConnectionDidFinishLoadingEventHandler(d_ConnectionDidFinishLoading);
                        d.ConnectionDidReceiveAuthenticationChallenge += new
NSURLConnection.ConnectionDidReceiveAuthenticationChallengeEventHandler(d_ConnectionDidReceiveAuthenticationChallenge);
                        d.ConnectionDidReceiveData += new
NSURLConnection.ConnectionDidReceiveDataEventHandler(d_ConnectionDidReceiveData);
                        d.ConnectionDidReceiveResponse += new
NSURLConnection.ConnectionDidReceiveResponseEventHandler(d_ConnectionDidReceiveResponse);
                        d.ConnectionWillCacheResponse += new
NSURLConnection.ConnectionWillCacheResponseEventHandler(d_ConnectionWillCacheResponse);
                        d.ConnectionWillSendRequestRedirectResponse += new
NSURLConnection.ConnectionWillSendRequestRedirectResponseEventHandler(d_ConnectionWillSendRequestRedirectResponse);
                        d.ConnectionDidSendBodyData += new
NSURLConnection.ConnectionDidSendBodyDataTotalBytesWrittenTotalBytesExpectedToWriteEventHandler(d_ConnectionDidSendBodyData);
                    });
                NSURLConnection.NSURLConnectionEventDispatcher @delegate =
new NSURLConnection.NSURLConnectionEventDispatcher();
                assignment(@delegate);
                NSURLConnection conn = new NSURLConnection(req, @delegate);

Also added some logging to
NSURLConnectionEventDispatcher.RespondsToSelector() and I do see in the log
some requests to see if my delegate responds to:
selector
connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:
selector connection:canAuthenticateAgainstProtectionSpace:
selector connection:needNewBodyStream:

But only these 3.  I added the ConnectionDidSendBodyData event, which is
also not called.  I did do the same code in obj-c and the same 3 selectors
are checked plus a few extra.  And the didSendBodyData selectors is called
in obj-c.

Because of the logging I know that the @delegate is being inspected by
NSURLConnection.  But after those 3 no selectors are called on
NSURLConnectionEventDispatcher.  I even tried just returning true to
respondsToSelector hoping to raise an error, but that did not.

Any help would be greatly appreciated.

Duane

On Sat, Nov 14, 2009 at 11:09 AM, Duane Wandless <du...@wandless.net> wrote:

> I'm trying to use NSURLConnection, mainly to take advantage of Apple's
> built in proxy detection.  However I cannot get the delegate to work.
>
> Any help in getting NSURLConnection to work would be greatly appreciated.
>
> NSURLConnection.Class.cs defines:
> public virtual Id Delegate
>         {
>             get { return ObjectiveCRuntime.SendMessage<Id>(this,
> "delegate"); }
>             set { ObjectiveCRuntime.SendMessage(this, "setDelegate:",
> value); }
>         }
>
> However there is no "delegate" selector defined on NSURLConnection so
> SetDelegate fails with:
> 2009-11-14 10:50:12.468 SimplePrototype[1356:5e03] -[NSURLConnection
> delegate]: unrecognized selector sent to instance 0x6d3b20
>
> Also if I try:
>             NSURLConnection.NSURLConnectionEventDispatcher d =  new
> NSURLConnection.NSURLConnectionEventDispatcher();
>             d.ConnectionDidFailWithError += new
> NSURLConnection.ConnectionDidFailWithErrorEventHandler(d_ConnectionDidFailWithError);
>             d.ConnectionDidFinishLoading += new
> NSURLConnection.ConnectionDidFinishLoadingEventHandler(d_ConnectionDidFinishLoading);
>             d.ConnectionDidReceiveData += new
> NSURLConnection.ConnectionDidReceiveDataEventHandler(d_ConnectionDidReceiveData);
>             d.ConnectionDidReceiveResponse += new
> NSURLConnection.ConnectionDidReceiveResponseEventHandler(d_ConnectionDidReceiveResponse);
>             NSURLConnection conn = new NSURLConnection(req, d);
>
> none of the callbacks are invoked.  I also tried creating a class that
> defined:
>         [ObjectiveCMessage("connection:didReceiveResponse:")]
>         public void didReceiveResponse(NSURLConnection conn, NSURLResponse
> resp)
>
> but that failed to receive a response either.  I also tried creating the
> connection with start immediately false and then calling start, again
> without success.
>
> Thanks,
> Duane
>
>

Reply via email to