-1

I'm uploading 1900 contacts on my server through a POST API call (AFNetworking). It is taking some time to get a response from the server. During the upload I want to show a progress bar to show an estimated remaining upload time, as I'm not uploading any file , I use json string to post parameters.

Please help me with this, through Google search I could not find any help regarding the upload or download API.

Jay Raval
  • 11
  • 4

1 Answers1

0

There are multiple answers on StackOverflow already answering your specific use case. For example have a look at this question: get progress from dataTaskWithURL in swift For your specific use case there are also already answers using AFNetworking: AFNetworking 3.x multipart form upload

To summarize, what you want to do is to 1. calculate the total amount of data you want to upload and the 2. total amount of data you already uploaded via the URLSession delegate methods.

Then you can bind this information to your UI element, for example your UIProgressView. Make sure that your upload tasks are asynchronous in order to have a non blocking upload task and to be able to update your UI while the upload is happening. This also means that other than your upload task your code to refresh the UI should run on the main thread. You can enforce this via DispatchQueue.main.async if needed.

dehlen
  • 7,325
  • 4
  • 43
  • 71
  • Im not uploading any file, I'm just posting json string of contacts in parameters. dehlen – Jay Raval Sep 14 '18 at 07:29
  • You still can use `setUploadProgressBlock:^(NSInteger bytesWritten,long long totalBytesWritten,long long totalBytesExpectedToWrite)` in order to track the number of bytes sent and the total amount of bytes like I stated above. – dehlen Sep 14 '18 at 07:32
  • I'm able to get upload progress, I want estimated time after uploading parameters to getting response from Server. – Jay Raval Sep 14 '18 at 07:34