Problems Getting Progress w/ NSProgressIndicator

286 views
Skip to first unread message

Hunter Hillegas

unread,
Jun 30, 2010, 1:12:51 PM6/30/10
to ASIHTTPRequest
I'm having some trouble getting progress indication to work and I was
hoping someone else could point me in the right direction.

A few notes:

* My upload is to S3.
* The upload works fine.
* The upload is async.
* The upload is using an ASINetworkQueue.
* The delegate of the queue is this class.
* The progress indicator is setup in a XIB.
* The progress indicator is bound to an outlet named
uploadProgressIndicator.
* Via the debugger, I have verified that uploadProgressIndicator is
not null.
* The NSProgressIndicator is not set to indeterminate.

Here's a code snippit showing the setup of the request and progress
indication:

ASIS3ObjectRequest *request = [ASIS3ObjectRequest
PUTRequestForFile:fileToSend withBucket:kS3BucketName key:s3FileName];
request.accessPolicy = ASIS3AccessPolicyPublicRead;
request.delegate = self;

[uploadProgressIndicator setDoubleValue:0];
[uploadProgressIndicator setMaxValue:0];
NSLog(@"Max: %f, Value: %f", [uploadProgressIndicator maxValue],
[uploadProgressIndicator doubleValue]);
[uploadQueue setUploadProgressDelegate:uploadProgressIndicator];

[uploadQueue addOperation:request];
[uploadQueue go];

The problem is that the indicator sits at 0% throughout the entire
operation and then hits 100% when the operation is complete.

Am I doing something stupidly wrong? What should I be checking?

Ben Copsey

unread,
Jun 30, 2010, 1:35:27 PM6/30/10
to asihttp...@googlegroups.com
Hi Hunter

> I'm having some trouble getting progress indication to work and I was
> hoping someone else could point me in the right direction.
>

> ...


>
> [uploadProgressIndicator setDoubleValue:0];
> [uploadProgressIndicator setMaxValue:0];

It shouldn't normally be necessary to reset the progress indicator, ASIHTTPRequest should do this for you.

> The problem is that the indicator sits at 0% throughout the entire
> operation and then hits 100% when the operation is complete.
>
> Am I doing something stupidly wrong? What should I be checking?

Did you set showAccurateProgress to YES on the queue?

Best

Ben

Brick

unread,
Jun 30, 2010, 5:33:32 PM6/30/10
to ASIHTTPRequest
I to am have in a similar problem but with a single upload. i created
a UIProgressView in my class like so

- (UIProgressView *)myProgressIndicator
{
if (myProgressIndicator == nil)
{
CGRect frame = CGRectMake(70.0, 400.0, kUIProgressBarWidth,
kUIProgressBarHeight);
myProgressIndicator = [[UIProgressView alloc]
initWithFrame:frame];
myProgressIndicator.progressViewStyle =
UIProgressViewStyleDefault;
myProgressIndicator.tag = 1;

[self.view addSubview:myProgressIndicator];
}
return myProgressIndicator;
}

then i call a method that has this code in it.

ASIFormDataRequest *request = [ASIFormDataRequest
requestWithURL:url];

[myProgressIndicator setProgress:0];
NSLog(@"Value: %f",[myProgressIndicator progress]);
[request setPostValue:cn forKey:@"txtCalName"];
[request setPostValue:genericImageName forKey:@"uploadedFile"];
[request setData:imageData withFileName:genericImageName
andContentType:@"image/jpeg" forKey:@"uploadedFile"];
[request setDelegate:self];
[request setUploadProgressDelegate:myProgressIndicator];
[request showAccurateProgress];
[request startAsynchronous];

NSLog(@"Value: %f", myProgressIndicator.progress);

But the progress bar simply fills in completely not gradually and the
NSLog values are always 0, but the image is uploaded

Hunter Hillegas

unread,
Jun 30, 2010, 6:22:57 PM6/30/10
to ASIHTTPRequest
Hey Ben,

The resetting of the progress indicator just came from the example
code on the Web site... Stripping that out and setting
showAccurateProgress to YES seems to have fixed it - thanks.

Hunter

Ben Copsey

unread,
Jul 1, 2010, 5:43:46 AM7/1/10
to asihttp...@googlegroups.com
Hi Hunter

> The resetting of the progress indicator just came from the example
> code on the Web site...

Ah, ok. Those examples were written a long time ago, I can't honestly remember if it used to be necessary to reset the indicator manually or not. It's not a big deal either way, if you do it, it shouldn't affect behaviour, but I've changed the sample code because it it's certainly confusing. Thanks for letting me know!

> Stripping that out and setting
> showAccurateProgress to YES seems to have fixed it - thanks.

Great stuff.

Best

Ben

Reply all
Reply to author
Forward
0 new messages