iPhone Upload Progress Bar

If you are developing for the iPhone and you have been utilizing the web components, you have probably noticed that while you can observe the downloading progress, via the NSConnection class, you are unable to hook into the outbound stream from the Cocoa Touch framework classes.   In order to solve this problem you need to go beneath the covers and use the CFNetwork class.

The CFNetwork class will allow you to monitor the inbound and outbound streams.  The NSConnection and NSRequest methods are actually built on top of their Core Foundation counterparts.

Here is a link to the apple documents relating to the CFNetwork Classes: http://developer.apple.com/iphone/library/documentation/Networking/Conceptual/CFNetwork/Introduction/Introduction.html

This whole system might look fairly complex and it is.  You need to understand about streams and headers and binary data and all that fun stuff, but luckily the guys over at All Seeing Interactive (http://www.allseeing-i.com) have devised a couple of classes that you can implement in your own code.

Now I have a minor critique of this code in that I don’t like the way that it’s ASIRequest object consumes a UIProgressView (or it’s Mac Equivalent) only.  Personally I like to have a little more control over how my progress bars update.  This may sound a little obtuse but consider the following scenario: Imagine you have a multi-stage upload and save that must first assemble some binary data, compress it and then upload it.  The progress bar then should have 1/3 of it used for each step.  With the current implementation the progress is assumed to go from 0% to 100%.

This really isn’t a big problem though because the code is available for download from their public repository at github.  A couple of minor changes and it is easy enough to simply provide an additional selector for the progress updating and voila, you have full control.

So to the guys over at All Seeing Interactive, thanks for the framework.  It gets us all going in the right direction.  Good Work!

Tags: , , , , ,

Comments

  • [...] BeefyApps Blog placed an observative post today on iPhone Upload Progress BarHere’s a quick excerptIf you are developing for the iPhone, as we at beefyapps are, and you have been utilizing the web components you have probably noticed that while you can observe t… [...]

  • Hi Jeff

    I’m glad you find ASIHTTPRequest useful.

    It’s true that ASIHTTPRequest masks you from some of the details regarding progress – I made this decision to make it easy to use in the most typical cases, but it does require a bit more work if you want to handle progress in a different way.

    There are a couple of approaches you could take that won’t involve modifying the ASIHTTPRequest classes:

    You could set a progress delegate that isn’t a UIProgressView – your progress delegate can be anything as long as it responds to setProgress:.

    If your upload is actually a single chunk of data that you’re going to reassemble on the server, an easier method is to use setShouldStreamPostDataFromDisk: (see http://allseeing-i.com/ASIHTTPRequest/How-to-use#streaming). When you do this, ASIHTTPRequest streams the request body from disk, and doesn’t have to hold it all in memory. You can then upload massive files without eating up memory, so there’s no need to break it into several requests.

    Ben

  • I knew it wasn’t too complicated and your code layout is clear and concise. Everything was well documented and easy to use.

    I will have to look at that setShouldStreamPostDataFromDisk: method, I have been working the new OS and the beta version seems to be more memory constrained. I am sure that much of that will be fixed for the release however.

Post a Comment

Your email is not published nor shared.