Pony Debugger

Episode #54 | 10 minutes | published on 02/21/2013
Subscribers Only
In this episode we take a look at Pony Debugger, a fantastic little tool by the fine folks at Square, to inspect HTTP traffic and dive into our Core Data model all via a Chrome inspector pane in the browser.

Episode Links

Installing ponyd (the server)

You first have to install a little python server that will accept connections from iOS clients:

curl -sk https://cloud.github.com/downloads/square/PonyDebugger/bootstrap-ponyd.py | \
  python - --ponyd-symlink=/usr/local/bin/ponyd ~/Library/PonyDebugger

You may also want to add this to your path. Once it is installed, you can run the server with ponyd serve --listen-interface= This starts up a web server that you can hit with Chrome at http://localhost:9000.

Installing the client framework in your app

Installation is (still) easiest with CocoaPods, even though the current podspecs (at the time of recording) had some incompatibilities. Copy the podspecs for SocketRocket and PonyDebugger to your project. Remove the commit hash requirements from the git reference, and make sure the SocketRocket version does not have a "-" in the version. For reference, look at the podspecs provided in the source code.

After that, run pod install to set up the Xcode project and link all dependencies.

Note: you won't want to ship with this running, so you should not configure the server unless you are running in a debug or adhoc build configuration.

Connecting to the server

In your app delegate, you can connect to the server using a URL:

[[PDDebugger defaultInstance] connectToURL:[NSURL URLWithString:@"ws://localhost:9000/device"]];

Once you're connected you can enable network debugging:

[[PDDebugger defaultInstance] enableNetworkTrafficDebugging];
[[PDDebugger defaultInstance] forwardAllNetworkTraffic];

Setting up core data is easy as well, you just have to hand it your instance of NSManagedObjectContext.

[[PDDebugger defaultInstance] enableCoreDataDebugging];

NSManagedObjectContext *context = [[[BeerInfoDataModel sharedDataModel] objectStore] 
[[PDDebugger defaultInstance] addManagedObjectContext:context withName:@"Main Context"];

Lastly, you can enable view hierarchy debugging with a single line:

[[PDDebugger defaultInstance] enableViewHierarchyDebugging];
blog comments powered by Disqus