Show progress bar when uploading image to my server

my application uploads the image to my server. I want to show this event with a progress bar.

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

I use these methods above to see a breakthrough in the console. but how do I do this in a nib file using a progress bar?

+3
source share
1 answer

If you use UIProgressView, you can set the progress in the connection: didSendBodyData: totalBytesWritten: totalBytesExpectedToWrite: a method like this:

float progress = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
float total = [[NSNumber numberWithInteger: totalBytesExpectedToWrite] floatValue];
progressView.progress = progress/total;
+15
source

Source: https://habr.com/ru/post/1721568/


All Articles