Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Firstly you're making starting the connection too complicated. Change to:</p> <pre><code>connection = [[NSURLConnection alloc] initWithRequest:request delegate:self] </code></pre> <p>Remove <code>[connection start]</code>. Now:</p> <ul> <li>Is your app definitely running the run loop normally? NSURLConnection requires this to work.</li> <li>Are you able to perform a synchronous load of the URL request?</li> <li>In the debugger, can you see that <code>url</code> is what you expect it to be? What is it?</li> <li>Is it possible that you're deallocating WSHelper before any delegate messages are received? NSURLConnection is asynchoronous after all.</li> </ul> <p>One does not need to do anything special to use NSURLConnection, it's a straightforward part of the Foundation framework. No special compiler settings required. No initialization before use. Nothing. Please don't start blindly trying stuff like bringing in CoreServices.Framework.</p> <p>As sending the request synchronously works, there must be something wrong with your handling of the asynchronous aspect. It could be:</p> <ul> <li>The runloop is not running in <code>NSDefaultRunLoopMode</code> so the connection is unable to schedule itself.</li> <li>Some other part of your code is calling <code>-cancel</code> on the connection before it has a chance to load.</li> <li>You are managing to deallocate the connection before it has a chance to load.</li> </ul> <h2>Real problem</h2> <p>Ah, in fact I've just realised what's going on. You are calling:</p> <pre><code>-[NSApp runModalForWindow:] </code></pre> <p><strong>Read the description of what this method does</strong>. It's not running the run loop like <code>NSURLConnection</code> expects. I'd say that really, you don't want to be presenting a window quite like this while running a URL connection for it.</p> <p>I'd also suggest that you implement the <code>-connection:didReceiveResponse:</code> delegate method too. You want to check here that the server is returning the expected status code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload