Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-09-2011, 04:45 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 57
kdp8791 is on a distinguished road
Default Mutiple NSURLConnection's and UIProgressView

I have setup multiple downloads within my app, what is the best way to go about setting up multiple progressView's.

Sample code below, but there is only one progressView.

Code:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
    filesize = [[NSNumber numberWithLong: [response expectedContentLength] ] retain];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
	[self updateDownloaded];
	[filesize release];
	[connection release];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
	[responseData appendData:data];
	NSNumber* curLength = [NSNumber numberWithLong:[responseData length] ];
	float progress = [curLength floatValue] / [filesize floatValue];
    
    progressView.progress = progress;

    
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
	NSLog(@"Download failed");
	
	[connection release];
}
If a user presses the first button the first progress begins as the file downloads. But when the second button is pressed, I would like the first to continue running as it is, but also add a second one by the second button and begin loading that as it downloads. Hopefully this is clear. Any help at all is appreciated.
__________________
kdp8791 is offline   Reply With Quote
Old 05-09-2011, 06:17 PM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 44
shabzcohelp is on a distinguished road
Default Answer broski

Code:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
 if (connection == firstConnection) {
    [responseData setLength:0];
    filesize = [[NSNumber numberWithLong: [response expectedContentLength] ] retain];
} else if (connection == secondConnection) {

//enter code here
}

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
 if (connection == firstConnection) {
	[self updateDownloaded];
	[filesize release];
	[connection release];
} else if (connection == secondConnection) {

//enter code here
}

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
 if (connection == firstConnection) {
	[responseData appendData:data];
	NSNumber* curLength = [NSNumber numberWithLong:[responseData length] ];
	float progress = [curLength floatValue] / [filesize floatValue];
    
    progressView.progress = progress;
} else if (connection == secondConnection) {

//enter code here
}

    
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
	NSLog(@"Download failed");
	
	[connection release];
}
shabzcohelp is offline   Reply With Quote
Old 05-10-2011, 04:47 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 57
kdp8791 is on a distinguished road
Default

Okay, so I think I get that, but I ended up trying to go another route. Instead of having MULTIPLE UIProgressView Bar's, I stuck with keeping one. So for example I have one button that downloads a 3MB file, and a second button that downloads a 4MB file. Assuming the user presses button one, the download begins and thereafter presses button 2, so the total file size would go from 3MB to 7MB. How would I got about adding that in this area of the code?

Code:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
	[responseData appendData:data];
	NSNumber* curLength = [NSNumber numberWithLong:[responseData length] ];
	float progress = [curLength floatValue] / [filesize floatValue];
    progressView.progress = progress;
}
__________________
kdp8791 is offline   Reply With Quote
Reply

Bookmarks

Tags
download, files, nsurlconnection, progressview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 352
9 members and 343 guests
dansparrow, iOS.Lover, lorrettaui53, MikaelBartlett, oztemel, pbart, PlutoPrime, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:58 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0