Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old Nov 22, 2012, 12:03 PM   #1
mycompuser
macrumors member
 
Join Date: May 2012
Uploading file using NSURLConnection

Dear all,

In my app developed in Lion using XCode, I need to determine the speed of the internet connection (upload speed) and for that I upload an file using NSURLConnection.
I extracted the code for formatting the xml and uploading from
http://blog.grio.com/2009/09/uploadi...om-iphone.html

I am using the async version of NSURLConnection to free up the main UI and also as I want the progress of the uploading process.

I have implemented the delegate methods provided by NSURLConnection they are.
Code:
//1. Method fired after upload is complete along with response code.
- (void)connection:(NSURLConnection *)theConnection didReceiveResponse:(NSURLResponse *)response

//2. Method fired when upload process fails.
- (void)connection:(NSURLConnection *)theConnection didFailWithError:(NSError *)error

//3. Method fired when upload process is completed.
- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection

//4. Fired periodically indicating no. of bytes sent/uploaded to the server (can be used to determine upload speed).
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
I find that even if I configure an invalid Upload URL for uploading of an file, the delegate method 4. above gets fired periodically during the uploading process giving the impression that the uploading is being performed successfully.

However during the end of the upload process with an invalid upload URL(when totalBytesWritten == totalBytesExpectedToWrite), the method 1. fires with an error http 404 indicating that the upload process has failed.

Is there a mechanism by which I can find whether the uploading of is being carried out successfully during the actual uploading of the file rather than waiting till the entire file is uploaded?.
mycompuser is offline   0 Reply With Quote

 
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Uploading to YouTube WerePig iPod touch 1 Feb 21, 2014 02:00 AM
Resolved: AFNetworking Vs NSURLConnection ? Tander iPhone/iPad Programming 3 Jul 30, 2013 05:36 AM
Error handling in NSURLConnection sendAsynchronousRequest waterskier2007 iPhone/iPad Programming 1 Mar 1, 2013 09:57 AM
Please help : Uploading WhySoSerious iPad 3 Aug 21, 2012 10:50 PM
Uploading pictures migdaddy iPad 3 Jun 10, 2012 12:34 AM

Forum Jump

All times are GMT -5. The time now is 05:51 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC