0

I have an app that uses 2 NSURLConnections to download information from a web server. They are each in completely different classes (class1 and class2). But for some reason after the one in class1 runs, and then I submit the other one in class2, instead of performing the request with the information provided in class2, it doesn't even submit a request and just automatically inherits the request from class1. So i'm just pulling in data from class1 into class2, which I do not want to do. Why can't I run this request from class2 without the class1 request interfering? Are you not able to use more than one NSURLConnection in an app?

NSMutableURLRequest *req1 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:submissionString]];


        [NSURLConnection connectionWithRequest:req1 delegate:self];
    }

}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    if (!_responseData1) {
        [self setResponseData1:[NSMutableData data]];
    }

    [_responseData1 appendData:data];
}


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)URLresponse {

    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)URLresponse;

    if (![httpResponse isKindOfClass:[NSHTTPURLResponse class]]) {
        NSLog(@"Unknown response type: %@", URLresponse);
        return;
    }
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {

    res1=[[NSString alloc] initWithData:_responseData1 encoding:NSUTF8StringEncoding];
Matt
  • 2,920
  • 6
  • 23
  • 33
  • Are both classes using the same URL? – rdelmar Aug 17 '12 at 22:01
  • No, completely different url's – Matt Aug 18 '12 at 21:33
  • Are you sure that you're actually calling the methods in both classes? If you put a log statement at the very top of the code you posted, in each class, do you get both of them logged correctly? – rdelmar Aug 18 '12 at 21:39
  • Yes they do. In class2 the nsmutableurlrequest is started with an ibaction, which originally worked. Then once I built the request code in class1 the one in class2 just stopped working properly even though the method is being called. And the one in class1 is logging and does work properly because the data is being displayed in a uitableview. – Matt Aug 19 '12 at 01:45
  • Well, I'm not really sure what I did, but I fixed it. Thanks! – Matt Aug 19 '12 at 02:09

0 Answers0