I'm trying to update a UIProgressView (that was created in IB) as I get chunks of data from an Asynch download using NSURLConnection. Without putting the async download into a background thread, the progress view update is all or nothing--that is, you don't see any activity in the progress view UNTIL the download is finished.
So I have the 4 key methods needed to do an asynch download: didReceiveData, didReceiveResponse, didFailWithError, and connectionDidFinishLoading. And I've got these 4 methods in the implementation of my ViewController class. I've tried to use "performSelectorInBackground" method to try to put such activity into a background thread but when I do (as the last line of code in my "viewDidLoad()" method), it just goes into la-la land and never executes any of the 4 callbacks mentioned above. I have a matching "performSelectorOnMainThread" call in the body of my "didReceiveData" method that invokes a simple method to update the UIProgressView attribute after calculating how much data was pulled down in the current chunk. When NOT using the "performSelectorInBackground" and "performSelectorOnMainThread" the 4 callback methods get called just fine and the download works. Some questions:
1. The method signature that I pass as the "selector" to the "performSelectorInBackground" is "-(void) startIt". Should this be "-(SEL) startIt" ? I get no complaints from the compiler using (void). Specifically, the call I use is:
and the details of my "startIt" method are:
2. Do I need to do any kind of thread creation or setup in my "startIt" method.
3. Is there any more direct way of connecting a UIProgressView to asynch NSURLConnection activity?
4. What XCode tools are there for monitoring thread activity in specific and the Cocoa framework in general that are recommended. I'd like to know where my app goes when it just sits there in "la-la land".
So I have the 4 key methods needed to do an asynch download: didReceiveData, didReceiveResponse, didFailWithError, and connectionDidFinishLoading. And I've got these 4 methods in the implementation of my ViewController class. I've tried to use "performSelectorInBackground" method to try to put such activity into a background thread but when I do (as the last line of code in my "viewDidLoad()" method), it just goes into la-la land and never executes any of the 4 callbacks mentioned above. I have a matching "performSelectorOnMainThread" call in the body of my "didReceiveData" method that invokes a simple method to update the UIProgressView attribute after calculating how much data was pulled down in the current chunk. When NOT using the "performSelectorInBackground" and "performSelectorOnMainThread" the 4 callback methods get called just fine and the download works. Some questions:
1. The method signature that I pass as the "selector" to the "performSelectorInBackground" is "-(void) startIt". Should this be "-(SEL) startIt" ? I get no complaints from the compiler using (void). Specifically, the call I use is:
Code:
[self performSelectorInBackground:@selector(startIt) withObject:nil];
and the details of my "startIt" method are:
Code:
- (void) startIt {
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
downloadURL = [[NSURL URLWithString:@"http://www.gutenberg.org/files/135/135.txt"] retain];
data = [[NSMutableData data] retain];
myConnection = [[[NSURLConnection alloc] initWithRequest: [NSURLRequest requestWithURL: downloadURL] delegate: self ] retain];
[autoreleasepool release];
}
2. Do I need to do any kind of thread creation or setup in my "startIt" method.
3. Is there any more direct way of connecting a UIProgressView to asynch NSURLConnection activity?
4. What XCode tools are there for monitoring thread activity in specific and the Cocoa framework in general that are recommended. I'd like to know where my app goes when it just sits there in "la-la land".