Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to wait the response from a http request in ios
    primarykey
    data
    text
    <p>Anybody knows how to wait the response of a http request? In my code, I am doing a http request to an url and then what i need to do, it is to check the http response in order to decide different treatment. I have something like this:</p> <pre><code>-(void)check{ [self fetchURL:@"http://something"]; if(response != nil || [response length] != 0){ do something.... } else{ do something else.... } } -(void)fetchURL:(NSString *)urlWeb{ NSURL *url = [NSURL URLWithString:urlWeb]; NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; [connection start]; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ NSLog(@"INSIDE OF didReceiveResponse"); } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ NSLog(@"INSIDE OF didFailWithError"); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ NSLog(@"INSIDE OF connectionDidFinishLoading"); } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ // Append the new data to receivedData. // receivedData is an instance variable declared elsewhere. NSLog(@"inside of didReceiveData"); response = [NSString stringWithUTF8String:[data bytes]]; NSLog(@"response: %@", response); } </code></pre> <p>I have been trying different options that I have seen around here, but i cant stop the execution of my code and wait for that answer...that means when I check the response of my http request, it always appears empty or with a nil reference... any help how to figure out?? thanks</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