June 21st, 2011, 03:02 PM
Problem with NSURLConnection
It's been a while since I worked with iPhone SDK so I'm a bit rusty. I have a problem here trying to "capture" the value obtained in didReceiveData method. Specifically, I have class A which is using NSURLConnection to obtain large XML data. I then parse this XML data in this class A.
This XML data contains id numbers for which a 3-rd party service we use provides pictures given that id. So, in a parsing loop of class A, for each id I pass it to class B which creates NSURLConnection to that 3-rd part service and returns a URL with image.
So, my class A then at each iteration needs to obtain image URL from class B and store it in it data structure.
My problem is that I am never able to obtain the value of image URL for class A to receive. I mean I get the URL image in class B:
But if I try to copy its value to a private NSString variable and use a "getter" method in class A, I get a blank string.
NSLog(@"Succeeded! Received %d bytes of data",[xmlData length]);
NSString *tempo = [[NSString alloc] initWithData:xmlData encoding:NSASCIIStringEncoding];
xmlData = [[NSMutableData data] retain];
imageString = [[NSString alloc] initWithData:xmlData encoding:NSASCIIStringEncoding];
/// IT WORKS HERE
NSLog(@"I GET MY URL IMAGE !!!! %@", imageString);
It seems that there is some kind of an independent process going on inside NSURLConnection delegate methods and I can't find a way to "capture" the value of the URL image that class B gets in its NSURLConnection method.
In other words, I can't find a way for class A to receive the value of URL image string which class B gets in its NSURLConnection procedure.
Any advise at how to make this work will greatly be appreciated.