Appendix A. Miscellaneous Hacks and Recipes

Only the major iPhone frameworks have been covered in this book. Dozens of smaller, proprietary frameworks exist on the iPhone waiting to be explored. Through a little bit of hacking, some of these smaller frameworks have proven themselves useful for one-off needs. A number of other interesting recipes have also been concocted for performing tasks such as initiating a phone call or setting the iPhone’s vibrator. This chapter covers some of the hacks and recipes we couldn’t fit anywhere else in the book.

Dumping the Screen

The UIApplication class sports a method named _dumpScreenContents that can be used to make a screenshot on the iPhone. The method causes a file named /tmp/foo_0.png to be written to disk.

To dump the screen contents from within your application, make sure to call the _dumpScreenContents method from your UIApplication class:

[ self _dumpScreenContents: nil ];

You’ll need to have at least a main window with a content view created to take a screenshot. Every call to _dumpScreenContents causes the file to be written to the same location, /tmp/foo_0.png, so be sure to move it out of the way if you’re taking multiple screenshots.

Example: Command-Line Screen Capture Utility

This example takes a snapshot of the screen from the command line, allowing the user to log in via SSH and capture the currently running application. Only iPhone firmware versions 1.x are able to take screenshots from the command line. Versions 2.x and newer can ...

Get iPhone Open Application Development, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.