Reputation: 3071
On my single view I have upload and download option of image and audio file, I successfully implemented the download code with progress bar indicating download progress.
I am having issue in showing uploading progress, currently I am using [NSURLConnection sendAsynchronousRequest:
but I also want to show upload progress, this method has no callback block or delegate function regarding data progress. So I tried to use connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:
but how this method will trigger?
For downloading I am doing this to trigger NSURLConnectionDataDelegate methods and getting my job done.
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
If i use [NSURLConnection connectionWithRequest:someReq delegate:self]
for uploading, I will be setting delegate twice in one file, first when uploading method is called and second when download method is called, Is this a correct approach?
Finally how [NSURLConnection sendAsynchronousRequest:
is useful, it has no delegate or callbacks regarding data progress, why to use it?
Upvotes: 0
Views: 240
Reputation: 25927
Downloading and uploading can be two different moments of the application. It does make sense to set self
twice as delegate, if you create twice the object that is responsible for starting the NSURLConnection
, otherwise no it doesn't make sense.
The complete method signature is sendAsynchronousRequest:queue:completionHandler:
which makes a huge different. In this case you don't need to set a delegate because the response comes in the handler (NSData
*).
Upvotes: 1