开发者

uiprogressview jumps to 99% then 100% using ASIFormDataRequest

I'm trying to implement a UIProgressView for an image upload so I set it up with

uploadProgress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
[uploadProgress setFrame:CGRectMake(85, 19, 150, 9)];

imageRequest = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://theurl.com"]];
[imageRequest setDelegate:self];
[imageRequest setDidFinishSelector:@selector(uploadedImage:)];
[imageRequest setDidFailSelector:@selector(asiRequestFailed:)];
[imageRequest setTimeOutSeconds:60];
[imageRequest addData:imgData forKey:@"file"];
[imageRequest addPostValue:[parameters yajl_JSONString] forKey:@"json"];
[imageRequest setUploadProgressDelegate:uploadProgress];
[imageR开发者_如何学JAVAequest setShowAccurateProgress:YES];
[imageRequest startAsynchronous];

It loads for awhile, then jumps to almost 100% then it gets to 100%, then after a couple seconds, it completes. Is there something I'm missing in my code, or do I need to do something on the server side?

Thanks


Tracking a Post operation is always going to have this issue. The data uploads, and then your app has to wait for the response from your server that it has completed successfully. The ASIFormDataRequest is aware of the incremental sending of data, so it can track this progress accurately up until the last bit of data is sent. It can't however, know how long your server will take to respond to confirm that the entire upload has been received successfully (when your didFinishSelector is called). Your upload is fast, and progress is tracked up to 99%, then sits at 99% until uploadImage is called, which signals it's completion, 100%.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜