0

I'm doing some kind of finding my device using this code:

NSOperationQueue* quququ;

int i=0;
for (i=0; i<256; i++) {
    //NSLog(@"%i",i);

    NSString *url=[NSString stringWithFormat:@"http://%i.%i.%i.%i/",myip1,myip2,myip3,i];
    //NSLog(@"urlGET = %@", url);

    NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1];

    [NSURLConnection sendAsynchronousRequest:request queue:quququ completionHandler:^(NSURLResponse *respons, NSData *data, NSError *error) { 

    //do smth
    NSLog(@"data: %ld bytes. res: %@, error: %@", (long)[data length], respons, error);

}];

what am i doing wrong? i receive the "exc_bad_access" error.

Horhe Garcia
  • 882
  • 1
  • 13
  • 28

1 Answers1

1

In the first line of your code, you just declare an NSOperationQueue reference, but did not create a NSOperationQueue object, that is the root cause of "EXC_BAD_ACCESS" error. You should assign queue with a NSOperationQueue object and then use it.

Change the first line of your code to

NSOperationQueue* quququ = [[[NSOperationQueue alloc] init] autorelease];

This will solve your problem.

Tony
  • 1,581
  • 11
  • 24
  • Thank you, u r right. Do u know how to get [response statusCode] from NSURLResponse ( not from NSHTTPURLResponse )? – Horhe Garcia Mar 11 '12 at 15:17
  • "Status code" is part of HTTP protocol, you are suppose to get the status code from NSHTTPURLResponse, which is a subclass of NSURLResponse, instead of NSURLResponse. Since you are sending a HTTP request, the `respons` object is actually a NSHTTPURLResponse object, so you can get status code like this: `[((NSHTTPURLResponse* ) respons) statusCode]` – Tony Mar 12 '12 at 06:04