Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>NSURLRequests are completely asynchronous anyway. If you need to make an NSURLRequest from a thread other than the main thread, I think the best way to do this is just <strong>make the <code>NSURLRequest</code></strong> <em><strong>from the main thread</em></strong>.</p> <pre><code>// Code running on _not the main thread_: [self performSelectorOnMainThread:@selector( SomeSelectorThatMakesNSURLRequest ) withObject:nil waitUntilDone:FALSE] ; // DON'T block this thread until the selector completes. </code></pre> <p>All this does is shoot off the HTTP request <em>from the main thread</em> (so that it actually works and doesn't mysteriously disappear). The HTTP response will come back into the callbacks as usual.</p> <p>If you want to do this with GCD, you can just go</p> <pre><code>// From NOT the main thread: dispatch_async( dispatch_get_main_queue(), ^{ // // Perform your HTTP request (this runs on the main thread) } ) ; </code></pre> <p>The <code>MAIN_QUEUE</code> runs on the main thread.</p> <p>So the first line of my HTTP get function looks like:</p> <pre><code>void Server::get( string queryString, function&lt;void (char*resp, int len) &gt; onSuccess, function&lt;void (char*resp, int len) &gt; onFail ) { if( ![NSThread isMainThread] ) { warning( "You are issuing an HTTP request on NOT the main thread. " "This is a problem because if your thread exits too early, " "I will be terminated and my delegates won't run" ) ; // From NOT the main thread: dispatch_async( dispatch_get_main_queue(), ^{ // Perform your HTTP request (this runs on the main thread) get( queryString, onSuccess, onFail ) ; // re-issue the same HTTP request, // but on the main thread. } ) ; return ; } // proceed with HTTP request normally } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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