Episode #54

Pony Debugger

10 minutes
Published on February 21, 2013

This video is only available to subscribers. Get access to this video and 586 others.

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=127.0.0.1. 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] 
    mainQueueManagedObjectContext];
[[PDDebugger defaultInstance] addManagedObjectContext:context withName:@"Main Context"];

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

[[PDDebugger defaultInstance] enableViewHierarchyDebugging];