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!