Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use sendAsynchronousRequest:queue:completionHandler:
    primarykey
    data
    text
    <p>Two part question</p> <p><strong>Part one:</strong> I am trying to create an ASynchronous request to my database. I am currently doing it Synchronously however I want to learn both ways to better my understanding of whats going on.</p> <p>Currently I have set up my Synchronous call like this.</p> <pre><code>- (IBAction)setRequestString:(NSString *)string { //Set database address NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8778/instacodeData/"]; // imac development //PHP file name is being set from the parent view [databaseURL appendString:string]; //call ASIHTTP delegates (Used to connect to database) NSURL *url = [NSURL URLWithString:databaseURL]; //SynchronousRequest to grab the data NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSError *error; NSURLResponse *response; NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; if (!result) { //Display error message here NSLog(@"Error"); } else { //TODO: set up stuff that needs to work on the data here. NSString* newStr = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]; NSLog(@"%@", newStr); } } </code></pre> <p>I think what I need to do is replace the call</p> <pre><code>NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; </code></pre> <p>with the ASynchronous version</p> <pre><code>sendAsynchronousRequest:queue:completionHandler: </code></pre> <p>however I'm not sure what to pass to queue or completionHandler... Any examples/solutions would be greatly appreciated.</p> <p><strong>Part two:</strong> I have been reading about multi tasking and I would like to support it by making sure my connection requests complete if there is an interrupt. I have been following this <a href="http://mobileorchard.com/ios-advanced-programming-understanding-ios-4-multitasking/" rel="noreferrer">example</a> </p> <p>In it it explains how to gain more time if an interrupt occurs, I understand what its doing.. but not how to apply it to this connection? if you have any examples/tutorials to help me figure out how to apply it that would be awesome!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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