Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (2024)

Table of Contents
iPhone & iPod touch Superguide iLounge Free iPod-iPhone Book4_p Take Control of iPhone and iPod touch Networking and Security iOS Forensic Analysis: for iPhone, iPad, and iPod touch iOS Forensic Analysis: for iPhone, iPad and iPod Touch iLounge iPod-iPhone Buyers Guide_08 iOS 5 Programming Pushing the Limits: Developing Extraordinary Mobile Apps for Apple iPhone, iPad, and iPod Touch IOS Forensic Analysis: for IPhone, IPad and IPod Touch iPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod touch iPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod touch (Wiley) iPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod Touch IPhone SDK 3 Programming: Advanced Mobile Development for Apple IPhone and IPod Touch Developpez des applications originales pour iPhone et iPod Touch iPhone-Apps entwickeln: Applikationen fur iPhone, iPad und iPod touch programmieren Spiele entwickeln für iPad, iPhone und iPod touch Pushing Limits Pushing Limits Pushing Limits Pushing the Limits Pushing Limits Chip-Alles ueber iPhone iPod und iTunes Pushing the Limits Beginning iPhone Development: Exploring the iPhone SDK Beginning iPhone Development: Exploring the iPhone SDK Pushing the Limits Beginning iPhone Development: Exploring the iPhone SDK iPhone Programming iPhone-Magazin iPhone For Dummies: Includes iPhone 3GS Cocoa and Objective-C: Up and Running: Foundations of Mac, iPhone, and iPod touch programming References
# Type 10 all call types 11 voice calls 12 data calls 13 faxes 16 SMS 18 all data services except SMS 19 all services except SMS 25 all asynchronous data services So for instance, to block SMS (for example, if you’re getting SMS messages that you don’t want), enter: *35*0000*16# 0000 is the default call barring code; if you have changed it, enter yours. To remove the call barring, enter: #35*0000# Don’t forget to tap “call” after entering each code.

Call Forwarding You can use GSM codes to set up call forwarding on your iPhone. The most common reason to do this is to forward calls to a landline when you are outside of cellular coverage. Make sure to check your carrier’s billing policies on call forwarding before enabling this feature. Use the following format for call forwarding commands:

156

iphone hacks

HACK # 6.01 Show Status: Set: Cancel: Reestablish: Cancel & Forget:

*## **

Code 002 all calls 004 busy, no answer, or out of coverage (useful for switching voicemail providers) 21 sets all options (all calls, busy, no answer, or out of coverage) 67 when busy 62 when out of coverage 61 when there is no answer To set the length of time for the phone to ring before forwarding, add “ *

apply to all calls only apply to voice calls only apply to data calls only apply to fax calls only apply to line 2 calls

So for instance, to forward all missed calls (ignored, cancelled, call waiting) to voicemail (Figure 6-2), enter: *004*

#

Figure 6-2 . Forwarding all missed calls

To check the status of redirection (Figure 6-3), enter: *#61#

chapter 06 - Use GSM Codes to Configure Phone Features

157

Figure 6-3 . Checking status of a redirection

To cancel redirections, enter:

Quick TIP

##002#

Fix the voicemail button on an unlocked phone

Enter *43# to activate call waiting; to deactivate, enter #43#.

If your voicemail button doesn’t work after unlocking your iphone, you can use the following procedure to set it up. Go to the “phone” screen, bring up the keypad, and enter the following: *5005*86*

#. Press call, and wait a few seconds. When the wait screen disappears, your voicemail button will now be connected to the number you entered. Unfortunately, some carriers use SIM cards that have hardcoded voicemail numbers, and this method will not work on those carriers.

Enter Field Test Mode Entering *3001#12345#* engages Field Test mode (Figure 6-4) to display more detailed technical information about the current cell network. You’ll also notice that your signal strength indicator is now showing strength in dB, instead of bars.

dd

To understand some of the terms used in Field Test mode: www.tele-servizi.com/Janus/engfield1.html

Figure 6-4 . Field Test mode

Display IMEI Entering *#06# shows the IMEI number. This is also printed on the back of your phone. Search Google for “GSM codes” to look for more codes that work with your particular carrier. —— Christopher Kurpinski & Damien Stolarz

158

iphone hacks

HACK # 6.02

Hack 6.02:

Add Speed Dial with Custom Icons

You can create an icon on your home screen that dials a frequently used phone number. Dialing numbers quickly and easily is a key feature of any mobile phone. But many iPhone dialing tasks take several more clicks than they need to. This hack will give you a one-click method of dialing from the home screen of your iPhone.

dd

Pressing the home button twice will take you directly to your phone number favorites list on the iPhone. Try it.

Ever wonder why your phone calls voicemail when you hold down the 1 key? Basically, it looks for the voicemail number stored on your SIM card, and calls that. And even though you can’t assign speed-dial numbers on the iPhone, that voicemail shortcut still exists (hold down the number one and it calls your voicemail center). If your SIM card allows you to change the voicemail number on your SIM card (some SIM cards, like the newer cards on T-Mobile America, do not), then you can use this to set up a single speed-dial number. Bring up the keypad on your phone, type the following code [Hack #6.01], and press the Call button: *5005*86*

# After the phone finishes processing, hold down the 1 key. If you’re lucky, it will dial the number you just assigned. If not, make sure that you’re entering the code correctly. If everything is correct, and it still doesn’t work, you may be out of luck. This hack can come in handy if you want to use an alternative voicemail provider [Hack #6.06], or if you want a quick way to call your most frequently used number. Best of all, if your carrier supports the visual voicemail feature, this should not affect your voicemail button.

Set Up Speed-Dial Shortcuts There are two basic methods for adding a speed-dial icon to your phone: creating a web clip and creating a new application. Speed dial via Web Clip The first method can be done without jailbreaking your phone and takes advantage of the Web Clip feature in Safari. Safari allows you to save bookmarks as an icon on your home page. This can be used to get one-touch access to frequently used websites, but in our case we’ll use it to generate speed-dial bookmarks. Most modern phones recognize URLs that begin with “tel://” as telephone numbers. We can take advantage of this by creating a bookmark to a “tel://” URL on the home page. It’s difficult to do this directly from Safari, so we’ll need to use a web service. The downside of this method is that depending on the way the web service is implemented, it may not be totally secure. Also, some services may actually route the link through their server, which would require your browser to navigate to their site before placing the call. Open Safari on your phone and navigate to

.tel.qlnk.net. Hit cancel, and then hit the bookmark button (Figure 6-5).

chapter 06 - Add Speed Dial with Custom Icons

159

Figure 6-5 . Making a tel.qlnk.net Web Clip

Instead of creating a bookmark, select “Add to Home Screen.” Enter the name that you want to use and select “Add.” You can also use “

.tel.qlnk.net/?picurl=http://path.to/photo” if you want to add a custom picture (Figure 6-6).

Figure 6-6 . A speed-dial Web Clip on the Springboard

Another site that offers a similar service is www.soft-use.com/speeddial. Enter the name, phone number, and (optionally) a link to an online image. Press “Generate,” and then “Tap for Shortcut” (Figure 6-7).

160

iphone hacks

HACK # 6.02 Figure 6-7 . Generating a soft-use.com speed-dial shortcut

Like before, cancel the call, and select the bookmark icon, then “Save to Homepage.” Both of these sites allow a custom image to be used, but it must exist on the Web. You cannot load an image from the phone, or a hard drive. Both services will add a new Web Clip to your home page. When you want to place a call, tap the icon. A question box will pop up and ask you to confirm the call. Select “Call,” and the phone number that you entered will be called. What’s happening here is that a bookmark is created using the tel:// protocol. Safari opens the bookmark, sees the “tel://” indicator, and knows that it is a phone number. For security reasons, Safari always has to ask permission before making a call, which is why you have to select “Call” before the call is placed. On a jailbroken phone, the process is even easier. Both of the previous methods still work, and you can also use urlclip (found in Erica Utilities) to directly add a Web Clip to your homepage. SSH [Hack #9.04] into your phone, or use the Terminal app, and type “urlclip

tel://,” where and are replaced with the name and phone number you want to use. This will add the speed-dial Web Clip to your home page, but with the default Safari icon displayed (Figure 6-8).

Figure 6-8 . A speed-dial button made with urlclip

chapter 06 - Add Speed Dial with Custom Icons

161

Speed dial via application The second method (on jailbroken phones) is to use the application TapDial. After installing, run TapDial and enter the name and phone number that you want to use. Instead of a Web Clip, TapDial actually creates a new application for each speed-dial number. Unlike the Web Clip methods, this is a one-press solution and does not ask for confirmation before calling (Figure 6-9).

Figure 6-9 . Using TapDial

Making It Look Good All of the demonstrated methods will add speed-dial icons to your phone, and some will even let you use custom pictures from the Web. But what if you want to use pictures from your laptop? Or the pictures already on your phone? Luckily, if your phone is jailbroken, there’s a way to do just that:

1. 2. 3. 4.

5. 6. 7. 8.

162

iphone hacks

Make sure that you have SSH installed on your phone [Hack #9.04]. Create a 58x58 PNG icon for your speed-dial number. Copy the icon(s) to your phone, using SCP or SFTP. SSH to your phone, and find the speed-dial icon that you want to change. a. If you used a Web Clip method, use find / -name "WebClips" to locate your Web Clip directory. For this example (Figure 6-10), it was located at /var/mobile/Library/ WebClips. If you have multiple Web Clips, enter each directory, and type “cat Info.plist” to see the name and phone number for that clip. b. If you used TapDial, use find / -name "

.app", where is the title of your speed-dial icon, to find the app. For this example (Figure 6-11), it was under /Applications/. Back up the existing icon (optional). Use cp icon.png icon.png.bak to back up the current icon. Copy your new icon to icon.png. For this example, we loaded the new icon into our home directory, which is the default. Simply type cp ~/ ./icon.png, where is the name of your new icon. Exit SSH. The new icon (Figure 6-12) won’t be used right away. You’ll need to use the respring application or restart the phone to refresh the icon.

HACK # 6.02 Figure 6-10 . Finding the Web Clips

Figure 6-11 . Copying the icon into the Web Clip

Figure 6-12 . Custom icon on a speed-dial button

Congratulations! You’ve got a personalized speed-dial icon. You can use this technique to create as many as you want.

A Quicker Way An app called CallMe was released for jailbroken phones, and is the best method yet of creating a speed-dial icon with a custom picture. It uses your contact list and imports the picture for that contact (Figure 6-13). With this tool, it’s easy to create and manage speed-dial icons. The only drawback is that sometimes you don’t want to use the same picture for an icon. For example, when the contact picture is a body shot, it might look good for phone calls, but not for an icon, so the method of adding custom pictures is still applicable in those cases.

chapter 06 - Add Speed Dial with Custom Icons

163

Figure 6-13 . CallMe using address book images

Can’t decide which method to use? Consider this; the Web Clip method requires two taps before placing a call, but your shortcuts won’t be lost if you upgrade your firmware. TapDial and CallMe are one-tap solutions, but if you upgrade your firmware, you’ll lose all your speed-dial icons.

One More Thing You can take icon customization one step further if you want to have flexible icon placement. The iPhone will not allow random placement of icons; it groups everything together. You can get around this by creating some blank icons. Here’s how: • •

• •

Use one of the previously described methods to create a Web Clip. Edit the Web Clip Info.plist file, and delete the title and URL sections (this prevents the name from appearing). Create a 58x58 transparent .png image, and load it into your phone using the methods described earlier. Find the Web Clip on your iPhone, and copy the transparent PNG to icon.png for that Web Clip. Restart Springboard on your phone, and you should have a transparent icon. Pressing it will launch Safari to a blank page. You can create as many of these as you need, and use them as placeholders, to space out the icons on your phone (Figure 6-14). —— Christopher Kurpinski

Figure 6-14 . A couple examples of custom icon arrangement using blank Web Clips

164

iphone hacks

HACK # 6.03

Hack 6.03:

Access Your Asterisk Voicemails on Your iPhone or iPod touch Upgrade your Asterisk server with special iPhone/iPod touch functionality. Asterisk is an open source engine for telephony. It often serves as a modern digital replacement for the traditional office PBX and can power a large internal company phone network. Many offices use Asterisk to implement their voicemail system. For more information on setting the server up for yourself, check out www.asterisk.org. The iPhone application is a plug-in to your existing Asterisk server that allows you to retrieve your voicemails easily over a web connection. It is implemented as a web application, served by Apache/ PHP on the Asterisk server. You’ll need to install a couple libraries to make sure that the plug-in can work: you’ll need a running Apache, PHP, and the lame libraries (so that you can encode MP3s). You can find full and up-to-date instructions at http://tinyurl.com/asteriskinstall.

Quick TIP You can read all about Asterisk in the O’Reilly book by the same name http://oreilly.com/ catalog/9780596510480/ index.html. You can also find the book online at www.asteriskdocs.org.

Once your server is configured to work with the Asterisk Voicemail for iPhone plug-in, you can access it by typing in the address into Safari. You’ll see a screen like Figure 6-15.

Figure 6-15 . The main screen for Asterisk voicemail for iPhone

From this screen, you can access any of the voicemails in your mailbox to listen to, move, delete, or call back. Voicemails play back on your phone as an MP3 (Figure 6-16).

chapter 06 - Access Your Asterisk Voicemails on Your iPhone or iPod touch

165

Figure 6-16 . Listen to, move, delete, or call back Asterisk voicemail

Having all your telephony on one device is very convenient, and this can bring your Asterisk-based desk voicemail conveniently to your phone.

Hack 6.04:

Access Your Vonage Voicemails on Your iPhone or iPod touch Vonagent lets you listen to your Vonage voicemails on your iPhone or iPod touch. If you have Vonage and want to access your voicemails away from home, on your iPhone or iPod touch, the Vonagent application will give you an experience as convenient as visual voicemail. The application is currently available for jailbroken phones, so you’ll need to access it using Cydia, by adding the http://intelliborn.com/cydiav source. You can go to www.vonagent.com for a stepby-step guide to this. Once you’ve got Vonagent installed and running, input your Vonage username and password. Hit Save, and the main screen should update with your information and preferences (Figure 6-17).

Figure 6-17 . Vonagent information filled in

By tapping on voicemails, you can get to your Vonage voicemails and listen to them (Figure 6-18). 166

iphone hacks

HACK # 6.04 #6.05 Figure 6-18 . Accessing and listening to a voicemail

Vonagent goes beyond Apple’s voicemail in that you can easily email a message if it needs to be forwarded to someone else to deal with, or if you want to save the information to your own inbox for later follow-up.

Hack 6.05:

Use Voice over IP on Your iPhone or Second-Generation iPod touch Several applications allow Voice over IP (VoIP) on your iPod touch or iPhone, allowing you to use your second-generation iPod touch as a phone or save your voice minutes on your iPhone. One of the drawbacks of the gateway-drug iPod is that you start craving iPhone features. Sure, you can usually get twice the storage on your iPod than the current iPhone—and it’s smaller—but you want to stay in touch and you don’t know why you can’t just make a phone call. Fortunately, because the second-generation iPod touch supports the microphone input, if you have iPhone-style headphones, it can make phone calls just like an iPhone—as long as you’re on a Wi-Fi network. Additionally, for iPhone users who want to use VoIP—either to save minutes, or because they are overseas and want to make cheap calls via Wi-Fi—there are several applications that allow you to accomplish this feat. SIP Session Initiation Protocol (SIP) is the language that VoIP applications use. So applications that support SIP allow you to hold voice conversations over the Internet. Usually, these applications can make free calls between SIP phones, and then, using a gateway, can make paid calls to traditional phone services. You can make a SIP account with a variety of vendors, and most of the VoIP apps that are distributed for Windows, Linux, and Mac OS X are usually bundled with some sort of SIP account so that you can pay them money to reach the PTSN (public telephone switch network; i.e., landlines and mobile phones). SIP accounts generally provide extremely cheap per-minute rates and are purchased much like prepaid calling cards. A good stable SIP account vendor is http://gizmo5.com. They also have a desktop application and offer a few free minutes of calls (i.e., no up-front payment required) so you can see whether SIP is for you before making a commitment.

chapter 06 - Use Voice over IP on Your iPhone or Second-Generation iPod touch

167

There are two features you can get with SIP gateways: call out, and call in. If you just have a SIP account, you can call to other SIP accounts essentially for free. If you want to make calls out to landlines, but you don’t care about receiving calls (on that number, anyway), then you pay only for SIP-out minutes. If you become so enamored with SIP that you put it on your iPhone, your iPod, and your desktop, so that people can call you on your PC or on your handheld, depending on where you are, you’ll need to get a phone number for incoming PTSN to SIP calls—a SIP-in number. Because there’s really no cost, it’s good to experiment with SIP on your desktop and get everything working there, because it eliminates variables when debugging your iPhone or iPod SIP connection. Fring Fring (Figure 6-19) is an App Store application based around instant messaging, but it also supports SIP. Like the various other multi-IM programs, it lets you use MSN, Google, ICQ, Twitter, Yahoo!, and AIM, but it additionally supports voice—so you can use it to communicate with Skype users, other Fring users, and also use the voice chat features of several IM clients (Figure 6-20).

Figure 6-19 . Fring chat add-ons

Additionally, Fring integrates a SIP account and gives you a number of options (Figure 6-21) of places to create an account, or you can add your preexisting SIP account. Fring’s system tunnels the voice traffic through their servers (a hundred milliseconds away in Europe) and out to the SIP network, instead of your call going straight to the person you’re calling, so this can sometimes add delay in the form of call latency.

168

iphone hacks

HACK # 6.04 #6.05 Figure 6-20 . Fring VoIP add-ons

When used with an iPod touch, you have the option to call out using SIP or to chat with contacts (Figure 6-21).

Figure 6-21 . Fring iPod touch contact options

The more options that you have configured, the more options you have to call. Figure 6-22 shows options on an iPhone to make a call via SIP, Skype, or the iPhone’s own GSM connection.

Figure 6-22 . Fring iPhone contact options

chapter 06 - Use Voice over IP on Your iPhone or Second-Generation iPod touch

169

truphone Another option for SIP calling and voice chat is the App Store app truphone (Figure 6-23).

Figure 6-23 . truphone call interface

truphone has a similar feature set as Fring: voice chat with other IM clients, Skype voice support; it also features an integrated SIP service provided by truphone that simplifies configuration of VoIP features. SiAX For jailbroken phones, SiAX (Figure 6-24) is an option. It does not have the Wi-Fi-only limitations of the App Store applications (it will work over the iPhone’s 3G network), and it has a few features that the previous applications lack, like the ability to use a STUN server (for getting through firewalls). SiAX also supports the Asterisk IAX protocol, so you can make calls through your Asterisk server.

Figure 6-24 . SiAX

Wi-Fi vs. 3G The App Store VoIP applications generally do not support 3G connections and function only when on Wi-Fi. Although SiAX supports 3G, Fring and truphone do not.

170

iphone hacks

HACK # 6.06 VoIPover3G is a native application (Figure 6-25), available via Cydia, that can trick applications on an app-by-app basis into thinking they’re on Wi-Fi. It works for truphone, Fring, and even the App Store and iTunes stores, so you can download larger items over 3G connections.

Figure 6-25 . VoIPover3G

With SIP, Skype, and Asterisk options for your iPhone and second-generation iPod touch, you can set up flexible phone options so that you can make your calls cheaply from anywhere you want.

Hack 6.06:

Get Visual Voicemail on T-Mobile or Other Carriers

You can simulate the visual voicemail feature on other carriers using a voicemail-to-email service and a push email account. As great as visual voicemail is—and it is pretty cool—there are still some things that it can’t do. It’s also a carrier-dependent feature, so you’ll lose the feature if you unlock your phone to use it on a carrier who doesn’t support it. Luckily, there are some services available that you can use to improve your voicemail no matter what carrier you’re on. Figure 6-26 shows Apple’s built-in visual voicemail.

Figure 6-26 . Visual voicemail

chapter 06 - Get Visual Voicemail on T-Mobile or Other Carriers

171

The basic features of visual voicemail are:

1. 2. 3.

Voicemail audio is pushed to your phone. You can see which voicemails you’ve listened to and which you haven’t. Voicemails are automatically “pushed” to your phone; that is, they’re usually ready to be listened to without making a phone call.

Visual Voice Email There are three basic steps to getting your pseudo visual voicemail enabled:

1. 2. 3.

Create a new push email account just for voicemails. Forward your voicemail to a third-party voicemail service. Have the service email your voicemails, attached as MP3s, to that email address.

Step 1: Create a new push email account for voicemails. Yahoo! provides free email accounts that are fortunately push-enabled on the iPhone. [Hack #3.01] shows you how to set one up. You can set some obscure address that no one would want that includes your phone number, like my-5551212, and you can even create rules on the Yahoo! side that automatically trash any email that does not come from your voicemail provider. Make sure that push is enabled and that your phone is receiving email messages from this address before the next step. Step 2: Subscribe to a free voicemail service. There are probably hundreds, if not thousands, of voicemail systems that you could choose. If you already have some sort of voicemail-to-email solution, you could just forward your phone to that. But for the purpose of this hack, we’ll use a nice free voicemail and digital fax service called K7.net (Figures 6-27 and 6-28). [Hack #6.07] discusses other voicemail options. Choose the settings shown in Figure 6-27—PCM for the sound and “send to my email” for receiving messages. Obviously, you should enter the email address that you configured in Step 1.

Figure 6-27 . K7.net signup

172

iphone hacks

HACK # 6.06 Figure 6-28 . K7.net signup confirmation

Step 3: Forward your voicemail to this new service. Forward voicemails to your new voicemail service, instead of that provided by your cell carrier, such as T-Mobile or AT&T. You can select which kinds of calls to forward: call waiting calls, or ignored calls, or missed calls, or all of them. The exact codes to press vary by carrier [Hack #6.01]. For instance, to set up call forwarding on your U.S. iPhone on AT&T, open the keypad on the phone, and enter the following: *004*

# , then press “Call” (Figure 6-29). Now, any missed calls you receive will be sent to your email system instead of your carrier’s voicemail system. Make sure to check your carrier’s billing policies on call forwarding before enabling this feature.

Figure 6-29 . K7.net forwarding confirmation

To clear this number and return to the original voicemail settings, type ##004#, then press “Call.” Your “visual voicemail” To see how it works, go into your email and select the account you set up. After you receive a few phone calls and let them go to voicemail, you should see a screen like Figure 6-30.

chapter 06 - Get Visual Voicemail on T-Mobile or Other Carriers

173

Figure 6-30 . Forwarded voicemail listing

When you click on one of the messages, you’ll be able to listen to it right away, as the voicemail has already been downloaded to your mail (Figure 6-31). Even if you go out of cell range, the voicemails are right there to be listened to—just like visual voicemail.

Figure 6-31 . Forwarded voicemail detail

The main drawback of using K7 in particular as a voicemail vendor is that they never show the number that called you in the body of the email—it’s only in the sender field. Other voicemail services vary in the way they include caller ID in the message. Thus, you can’t use the iPhone’s number recognition feature and simply click the number to call back. Also, because the numbers are not integrated with the address book, you can’t see your address book entry; you see only the number of who’s calling. On the other hand, this messaging approach has some advantages over visual voicemail. Because voicemails are on an email account, you can access your voicemails from a desktop computer, if your phone battery goes dead (Figure 6-32). And this gives you an archive as well. So if you’re one of those people who likes to hold on to old voicemail messages for posterity or recordkeeping, you’ve got them. And if the voicemail would be better handled by someone else you work with, you can forward it on to them.

174

iphone hacks

HACK # 6.07 Figure 6-32 . Forwarded voicemail in desktop email client

—— Christopher Kurpinski & Damien Stolarz

Hack 6.07:

Automatically Translate Your Voicemails to Text

A number of companies now offer the ability to translate your voicemails to text, so that you can easily read them instead of having to listen. One of the recent features to appear in the telephony scene is automatic voicemail-to-text translation. It works like this:

1. 2. 3.

You forward your phone’s voicemail service to the new service, and set your outgoing message. When people leave you a voicemail, up to one minute of that message is transcribed by a combination of machine translation and anonymous human translation. The translated message is then sent to you, either in an SMS, an email, or both.

The email usually comes with the audio message itself attached as a media file, so you can play back the full message or parts that the translator missed or misunderstood. In an age of venture-funded free services, why does it cost so much? It's because they’re actually paying people to do the translation. Computer-based translation just isn’t advanced enough to handle speech-to-text. By using an army of workers who get paid per translation, they are able to scale. But because these translations cost real money, each of the companies offering this service still has to charge something, and thus there are limits on the length of messages (between 15 seconds and a minute) and how many messages they will translate in a month.

Various Services It seems like a new telephony company starts up every 15 seconds, given the amount of competition in this area (theoretically, a good thing for consumers). Current providers of voicemailto-text include: CallWave GotVoice PhoneTag SpinVox VoiceCloud YouMail

www.callwave.com www.gotvoice.com www.phonetag.com www.spinvox.com www.voicecloud.com www.youmail.com

chapter 06 - Automatically Translate Your Voicemails to Text

175

The services vary tremendously with regard to the quality of translations—even from day to day. They are also naturally affected by issues such as recording quality and the accent of the people who leave you messages. In the U.S. market, the popular U.K.-based SpinVox (Figure 6-33) service is provided by another company, Ureach.com. For $10 a month, they offer about 40 translations. For some people, that’s about three days of voicemail, so you’ll definitely need to get on an all-you-can-eat plan. The problem is that there’s a fixed cost for translations and the quality of the translations may suffer if you opt for this. Some of the other services, such as YouMail, offer (limited) “unlimited” translations, and even have options for translating only the first 15 seconds of the message—so you can get the gist of it and return the call if you need to.

Figure 6-33 . SpinVox

SpinVox/Ureach Here are some examples of translations through SpinVox/Ureach: Example 1: “Mrs. Dollards(?) it’s....Anyway it’s 8:48 and I’m gonna phone at 9:00 at Mike’s office and then I’m gonna be prepared for that conference call. If you got the message and got my information from last night, I’d called and said to you I think you got an email coz it was sent out to both of us but don’t know if you’ve had the information, if you don’t I can give it you.” Sadly, Mr. Stolarz became “Mrs. Dollards.” Example 2: “Hi Bro I have a habit of writing text messages and sending them to the wrong people. That message was for, for Tina cos she wrote where are you, and I wrote working where are you? But, out of context, just you receiving it, you probably, it sounds like you were supposed to be here and you weren’t and I’m like, where are you? Exclamation point. But it wasn’t for you. So don’t be alarmed. But it is a funny slip of some sorts cos I did wanna find out when you were next available to come over and stuff. So anyway give me a call. Ok bye” As you can guess, the translations from SpinVox are very accurate; it’s mainly names that give them trouble. VoiceCloud Here’s another example of translations, this time from VoiceCloud:

176

iphone hacks

HACK # 6.08 Example 1: Hi, I just wanted to let you know that I sold the book case for a 140 dollars to a nice young couple who had just tried to go to Ikea yesterday and buy mine but Ikea was sold out so they were very happy to find the discounted one that they could come get today, that was brand new, so anyway that was a cute story, it all worked out nicely, I have a 140 dollars and the boxes are out of the house, yea, ok bye... Voice-to-Text by VoiceCloud Other service features A differentiating feature of one of the services—YouMail—is that in addition to transcription, you can have a custom greeting that's based on caller ID. So if you have a business greeting but you don’t want to give the cold leave-a-message-I-can’t-talk-right-now to friends and family, you can enter them into your address book and give them friendly customized greetings based on MP3s you upload. You can even implement blacklists, so you can outright refuse to take a message from numbers of people you don’t like. The main problem with all of these services is that if you have a lot of voicemails, you’re just going to blow out most of their translation plans. And the few services that offer “unlimited” transcriptions aren’t necessarily going to give you the same results. Figure 6-34 pretty much sums up how your translations get used up if you’re playing cell-phone tag with bad reception.

Figure 6-34 . SpinVox sample text

It’s quite a remarkable fact that some fine gentleman or lady on the other side of the world stayed up late and got paid US$0.10 to memorialize AT&T’s lack of cell coverage on the 405 by translating a message to that effect. It’s also, to many, a bit eerie. Most people assume that voicemails are private messages, destined only for the listener, and the prospect that an angry or a flirty message will be faithfully typed in by a human agent, perhaps in India, is unnerving. But to a business user who only occasionally gets racy phone calls, the slight reduction in privacy may be worth it for the convenience of sifting through voicemails during a time-wasting meeting.

Hack 6.08:

Update Twitter or Your Blog with a Phone Call

You can use several of the digital transcription services to speak short text updates sent directly to Twitter or a blog. One of the more popular phenomena of late is micro-blogging—the posting of one- or twosentence SMS-sized postings to Twitter or to a social network as “status messages.” For one of the cool kids who used to have a .plan file just like John Carmack, leaving status messages is nothing new. But updates are expected much faster now, first with instant messaging, and now with Facebook and tweets—and sometimes you’re not in a position to type. Some of the services in [Hack #6.07] offer the ability to post directly to Twitter. Jott (www.jott.com; Figure 6-35) is designed around the concept of to-do lists, allowing you to leave voice notes for yourself that get automatically translated to text to-do items in your lists. chapter 06 - Update Twitter or Your Blog with a Phone Call

177

However, this same microtranslation service can be used for free to speak 15-second updates to Twitter or a blog—just long enough to fill those 140 characters.

Figure 6-35 . Jott

To use the Jott service, register for their free plan, enter your phone number, and then dial 866JOTT-123. Jott knows who you are and asks “who do you want to Jott?” You say “twitter” and then speak your tweet. It will post it within a few minutes. SpinVox offers a similar service, allowing you to post to Twitter, Jaiku, and Facebook. Once again, the service is free; you just sign up (Figure 6-36) and call the number they give you: +1-877-5-SPOKEN.

Figure 6-36 . SpinVox signup

178

iphone hacks

HACK # 6.08 The service recognizes your phone number, and voilà: your translated text shows up on Facebook and Twitter (Figure 6-37).

Figure 6-37 . SpinVox-rendered text on Facebook

If you need to update more than just Facebook and Twitter, metaposting service called Ping.fm takes posts and then reposts them to any other service you can think of (Figure 6-38). It uses SpinVox as its speech-to-text engine and then posts the message simultaneously to whatever service you designate. Now, all your social networks will be updated with the minutiae—or brilliant and sudden insights—of your life. It gives you a number to call and greets you with a very short “leave a message,” and thus is well suited to rapid impulse posting. You can even set up categories, so that your voice-based posts target specific subsets of your online services, and designate whether they constitute a “status update” (i.e., what you’re doing) or a microblog of something that you wanted to say.

Figure 6-38 . Ping.fm supported services

Other Services While you’re trying these services out for blogging, you may find that their posting features are useful for other hands-free activities. For instance, the paid SpinVox features allow you to use your voice to send a text message or email to people—very useful when you need to email a colleague who isn’t answering their phone, or when you need to get the thoughts out of your head and into their inbox. Because so many of these services offer free trials or services, there’s no harm in trying them all. reQall (www.reqall.com) and Dial2Do (www.dial2do.com) compete with Jott and are worth a look. chapter 06 - Update Twitter or Your Blog with a Phone Call

179

Hack 6.09:

Create a Podcast While Driving

You can create a podcast—a blog with downloadable MP3 files— just by making a phone call. If you live in a major U.S. city, there’s a good chance that you spend hours a day in a vehicle. That gives you lots of time to make hands-free cellular calls and listen to media on your iPhone. But once you’ve listened to all your books on tape once, all your music twice, and done every course on iTunes U, it’s time to actually start creating content yourself on the go. There are many different services that allow you to make a podcast using only your phone. For our purposes here, we will use Gcast (www.gcast.com; see Figure 6-39). It’s fairly quick to get up and running.

Figure 6-39 . Gcast’s main page

Creating a Gcast account is straightforward. Once you’ve created an account, you can call in to create your first podcast post. Calling in a podcast is easy. Dial 1-888-654-2278 from the phone number that you entered during account creation. Then type in your chosen PIN on that same screen. The automated service will then start recording, and you can start producing content (by speaking words into your phone). When you’re finished, press #. Then you can choose to scrap your recorded rambling and try again, or go ahead and save and/or post it online. Then hang up. In about five minutes time, the podcast should be posted online. Like any good podcast, people can subscribe to your Gcast in many different ways. Although any RSS reader will work, one of the more popular ways to subscribe to a podcast is via iTunes (Figure 6-40).

Figure 6-40 . Current options for subscribing to a Gcast podcast

180

iphone hacks

HACK # 6.09 The Gcast Subscribe with iTunes link gives you an XML link that you can use to add your podcast to your iTunes. The link should look something like this: www.gcast.com/u/iphonehacks/main.xml You can put this link on your website or email it to people; they should be able to read it in any RSS reader or podcast client. If you specifically want to target iTunes, use a special “launch iTunes” URL: itpc://www.gcast.com/u/iphonehacks/main.xml You can see how the podcast looks in iTunes in Figure 6-41.

Figure 6-41 . A Gcast podcast in the context of iTunes

Other Options Gcast is a great option if you want a simple podcast that you are going to promote on your own, through your website, or on your text blog. If you’d like other options, such as systems that allow you to do multiparty calls or that promote your blog to an audience, there are a number of other options, including these: Hipcast TalkShoe Gabcast Yodio

www.audioblog.com www.talkshoe.com www.gabcast.com www.yodio.com

chapter 06 - Create a Podcast While Driving

181

07

Unlocking and Activation In the world of GSM-based cellular providers, it is the SIM card, not the phone, that determines what network you connect to. Some people have a collection of GSM phones and swap their SIM card between them (Figure 7-1). It is even a good backup strategy for the mobile businessperson to have two phones, in case one breaks or runs out of battery charge. Figure 7-1. SIM card

Because the iPhone is a GSM phone, it is physically capable of connecting to most GSM networks. Many mobile phones around the world are subsidized. The manufacturer expects to make $300USD, $500, or more on the phone. Instead, it is sold for $100, $200, or given away “free” for consumers who agree to be locked in to a contract for a year or longer. You pay for part of your phone, and your mobile carrier pays for part of it, in exchange for having you as a customer for a while. And if you leave early, you have to pay to break your contract. You’d think that this would be enough for people to stick with a carrier. But there’s also exclusivity. Any mobile phone vendor is free to make exclusive deals with carriers, so that they can have a limited-time “exclusive” on a hot new phone. Yet even when they sell the same phone to all carriers in a market, they still have a habit of locking the phones, so that phones sold by a given carrier will work only with SIM cards from that carrier. 182

iphone hacks

HACK # 

Methods of Unlocking The goal of unlocking is to remove or change the code that prevents a phone from working on any GSM carrier. The most common methods include the following:

1. 2.

3. 4.

A sanctioned software unlock. This is the cleanest method. In this approach, the carrier or manufacturer does something to release the phone from its GSM bonds [Hack #7.01]. A hacked software unlock. In this approach, the method of locking is reverse-engineered, and some exploit is used to bypass or defeat it. Some of these changes can be permanent and resistant to new upgrades, but some are brittle, dependent on software versions, and break whenever the phone’s software is updated (which, for iPhones, is often) [Hack #7.02]. SIM cloning hacks, which replace the SIM with a SIM that has been copied, with alterations, to satisfy the phone’s need for carrier X while letting it communicate with carrier Y [Hack #7.03]. “Turbo-SIM” hacks, which work by inserting a small shim circuit between the carrier SIM card and the phone tricks the phone, the SIM, and the carrier network into thinking everything is normal [Hack #7.04].

General Unlocking Advice If you have a sanctioned unlock from Apple [Hack #7.01], there’s nothing to do. Your iPhone will work with any SIM card worldwide, and you can upgrade your firmware at will. For any of the various other methods of unlocking, you’re playing a game of cat-and-mouse with Apple. And although the first-generation iPhones are thoroughly unlockable, the 3G iPhone have been increasingly harder to unlock, as will, presumably, future iPhones.

If you have unlocked your iPhone, don’t upgrade your firmware when a new version is released! As new firmware versions are released, Apple clamps down on existing unlocking methods, causing them to break. It’s best to wait until more information pertaining to each new release has been gathered by the iPhone hacking community. With more knowledge about the firmware, you’ll have a better idea about what steps should be taken to assure that the upgrade goes smoothly. Initially, all the simple unlocking hacks used prior to the update may not work on the new firmware version. At first, the only unlocking method may be a complicated command-line hack that requires many steps. Even if the procedure goes flawlessly, these early unlocking hacks may still have a low success rate. These hacks may be too complex for the average user, thus limiting the number of iPhone owners who can benefit from such a method. Once the iPhone hacking community has had sufficient time to examine the details of the new firmware version, simple, easy-to-use applications for unlocking will slowly begin to emerge, and will phase out the complicated hacks that were developed initially. Around that time, the usual suspects [Hack #2.06] start to come to a consensus about which unlocking solution works with the latest firmware.

chapter 07 - unlocking and chapter activation 07 -

183

All hail those intrepid volunteers devoted to the noble cause of testing cutting edge, untested, and possibly dangerous unlocking techniques!

Hack 7.01:

Buy an Unlocked iPhone from Apple

If money is no object, you can purchase an unlocked iPhone. If you have enough money, in some regions, such as Hong Kong, Belgium, Italy, and Australia, you can purchase an unlocked iPhone. Insert your SIM chip from any carrier, activate, and you’re done (Figure 7-2).

Figure 7-2. Unlocking in iTunes (screenshot courtesy of Iain Rauch)

This is by far the best and potentially the easiest unlocking solution. You’ll pay a full, unsubsidized list price, which may be shocking, but not much more shocking than the original price of the iPhone at $600USD at release. In Hong Kong for instance, phones range between $700–$800USD for the 8GB and 16GB 3G models. Depending on exchange rates, you may do better. For instance, Figure 7-3 shows an unlocked 8GB iPhone 3G for approximately $634 plus another $55 or so for shipping.

184

iphone hacks

HACK # 7.02 Figure 7-3. eBay sells unlocked iPhones

There are a few drawbacks to this approach:

1. 2.

3.

You’re buying something with potentially less protection under domestic trade law, that takes a while to arrive, and that is subject to the vagaries of international commerce. Your warranty situation may be uncertain. If you walk into an Apple store in California with a new phone from Australia with a problem, will they cover it under warranty? And even if the answer is yes, if you have to swap phones, they are unlikely to have an unlocked replacement on hand and will probably refer you to the Apple office in the country the phone came from. These phones are expensive.

However, the advantages of having an Apple-unlocked phone are numerous. For one thing, you can be certain that no future Apple software upgrade is going to be designed to disable your unlock. Thus, you don’t have to fear upgrades, and you can stay current with the rest of the iPhone software world. Also, your phone may have excellent resale value should you want to upgrade—unlocked phones have a brisk trade online.

Hack 7.02:

Unlock Your iPhone with Software

Free your phone with free software—and a little free time. For the original iPhone and 3G iPhone, there have been many exploits that have led to a number of software-based unlocking solutions. Although all of these techniques eventually reduce to “run this program and click unlock,” the tremendous amount of mental gymnastics and brilliant reverse engineering that go into them is admirable. It’s possible that the world’s most hyped phone has become the world’s most hacked phone, because whether you’re looking for fame or fortune, both can be found in the iPhone unlocking arena. The very first iPhone unlock was achieved through hardware [Hack #7.03], but almost immediately a number of software solutions came out. Usually, jailbreaking and unlocking go hand in hand, and the graphical applications used for jailbreaking [Hack #1.03] are usually used for unlocking. Jailbreaking and unlocking both depend on exploits, which are essentially bugs or features with side effects that can be used to gain control of parts of the phone. Finding exploits is painstaking work consisting of decoding thousands of raw, fine-grained instructions to various unfamiliar chips,

chapter 07 - Unlock Your iPhone with Software

185

tracing them step by step, and trying to see how they work. It took almost six months for hacks in the 3G iPhone baseband to be discovered and exploited for unlocking. Many exploits have been developed for jailbreaking phones: unlocking is a more difficult task. Jailbreaking simply changes some settings on the flash drive to allow unsigned third-party applications, but unlocking requires sophisticated alteration of the baseband software, and requires an understanding of cellular protocols, baseband programming, and the security layers added to the equation with Apple’s iTunes-based phone activation system.

How Does It Work? As described in [Hack #2.01], there are two “brains” in the iPhone: the baseband, and the iPhone ARM CPU. The baseband is the “cell phone brain” of the iPhone (Figure 7-4), and it is this chip and its associated code that prevents or allows communication with the SIM card.

Figure 7-4. iPhone baseband boot sequence and CPU boot sequence

iPhone Baseband Boot Sequence

Infineon S-Gold 2 GSM Processor “Baseband”

Baseband Bootrom first code to run

Baseband Bootloader checks signatures, installs updates

iPhone CPU Boot Sequence

Baseband Firmware main instruction set

Samsung S5L8900 ARM11 CPU

Virtual ROM (VROM) copied from ROM

Low Level Bootloader (LLB) checks iBoot’s signature

iBoot—also runs Recovery Mode

186

iphone hacks

Darwin Kernel

Mobile OS X

HACK # 7.02 In a sanctioned unlock [Hack #7.01], there is a section of the baseband called the “seczone” where the lock state (unlocked or locked, and associated information) is stored on the phone. In the seczone is stored a token, a combination of information unique to every phone, including its IMEI (International Mobile Equipment Identity) number and a unique device ID. When an iPhone is activated, or unlocked through sanctioned means, this token is sent to Apple’s servers, and Apple uses encryption technology to digitally sign a “permission slip” for this token that is sent back to the phone to activate or unlock. iTunes sends this information to the iPhone, and the iPhone obeys the unlock or activation only if the token is properly signed by Apple. Because encryption technology is a strong defense, no one has been able to crack Apple’s code directly and create an authentic Apple signature. Rather, they have taken the approach of making the iPhone ignore these instructions from the mothership. And every time that the iPhone is updated, these “don’t listen to Apple” instructions inserted by hackers tend to be erased or overwritten, and the phone made more resistant to these breaches of loyalty. For the original iPhone, several major software unlocking techniques were developed. •

anySIM (http://code.google.com/p/devteam-anysim): anySIM (Figure 7-5) was originally available only in a paid application, but once alternative unlocking methods became available, it was open sourced. The first anySIM technique simply disabled signature checks in the baseband so that any attempt to verify an Apple signature would say “success.” This achieved the goal of unlocking, but was sensitive to restores, in that each time a new baseband firmware was released by Apple, it would undo the effects of this hack and the hack would need to be reapplied. An unfortunate side effect of this hack was that it irreversibly altered part of the baseband (the locktable, a section relating to lock status), and this resulted in temporary bricking when new basebands were installed. Virginization software was developed—this software could write virgin, locked locktables back to the device. An improved version of anySIM changed the baseband (but not the seczone portion of the baseband or the locktables) so that any MCC/MNC pair (Mobile Country Code/Mobile Network Code, used to identify a cell network) would appear to be valid. iphoneSimFree (www.iphonesimfree.com): Often abbreviated as IPSF, iphoneSimFree was a software unlock that works differently from anySIM—it is able to survive firmware updates. This hack changed the lockstate table in the seczone to unlocked, and then exploited several bugs: one in the RSA decryption parsing in the 3.9 bootloader and one in a data validation check, resulting in a token that appeared validly signed. Because the token itself is stored in the seczone, which is not updated by baseband updates, this particular hack survived firmware upgrades.

Figure 7-5. anySIM

chapter 07 - Unlock Your iPhone with Software

187

BootNeuter (for Original iPhone) A very stable method of unlocking the original iPhone was developed by the iPhone Dev Team and incorporated into the Pwnage software. This incorporates the various hacks mentioned previously, including repairs for common ravages of earlier unlocking techniques. BootNeuter can be installed in Cydia (Figure 7-6) or can be automatically installed when you create a jailbreak firmware image [Hack #1.03] and apply it to your phone (Figure 7-6). BootNeuter allows you to switch between the 3.9 or 4.6 bootloader. “Neutering” your bootloader allows a modified bootloader to be considered valid by the iPhone. From there it is a simple operation to unlock the phone. FakeBlank is a modified version of the 3.9 bootloader (a 4.6 FakeBlank is also available) that “blanks” a section of memory so that advanced bootrom hacking can be done and if trouble arises, the hacker can “roll back” their bootloader. If you aren’t experimenting with bootloader patches (you’ll know if you are) and just want an unlock, then you can leave the default settings.

Figure 7-6. BootNeuter

Yellowsn0w (for iPhone 3G) The iPhone 3G was released in the summer of 2008, but it took until New Year’s Eve of that year to unlock it via software. This unlock was far more difficult to accomplish than the first-generation unlock because more signature checking and software verification were added (specifically, the bootrom checks to see whether the 3G bootloader has been altered at boot). Yellowsn0w gets around this problem by loading an in-memory process that, after booting, tricks the phone into thinking it is unlocked. Because the unlock is simply a startup item, you can toggle the unlocked state with applications like BossPrefs (available on Cydia) or simply uninstall the program when you don’t need it. Like BootNeuter for first-generation iPhones, Yellowsn0w can be installed with Pwnage or via Cydia (Figure 7-7).

188

iphone hacks

HACK # 7.03 Figure 7-7. Yellowsn0w

Hack 7.03:

Unlock Your iPhone with a SIM Hack

You can use a locked phone on a different carrier with a physical hack to the SIM card. As mentioned in [Hack #7.02], the second method of the anySIM software hack changed the baseband so that any MCC/MNC pair (used to identify a cell network) portion of the phone’s IMSI (International Mobile Subscriber Identity) would appear to be a valid pair. Even if you can’t successfully hack the baseband—for instance, on a 3G iPhone—there is a hardware method for doing the same thing. As there already existed a large market for unlocking phones prior to the iPhone, many companies were already producing solutions for hacking SIM cards. Bladox, a Czech Republic–based SIM test tool manufacturer, introduced the Turbo-SIM in 2004. This clever device consisted of a thin circuit board shaped like a SIM card, and a tiny microcontroller (Figure 7-8). By cutting a tiny square out of the plastic casing of the SIM card (which did not affect the SIM card’s normal functioning), the Turbo-SIM could piggyback the SIM card, intercept its communication with the phone, and mediate between the two to make sure they “agreed.” SIM card sandwich hacks of this nature were some of the most consistently effective for firstgeneration iPhones, and are currently the only effective solutions for iPhone 3G hacking. As with many hacking solutions, a game of cat-and-mouse has ensued, and many of these SIM piggyback cards ceased to work when firmware 2.2 was released for the iPhone. Because the piggyback SIM has a reprogrammable microcontroller, they can be upgraded with new firmware (with the right programming equipment) to work around new problems. Example: i3gSim All this unlocking method requires is that you purchase the unlocking tool, and sandwich it with your non-AT&T SIM card. This tool works by tricking your iPhone into thinking that the proper AT&T

chapter 07 - Unlock Your iPhone with a SIM Hack

189

SIM (or whatever network your iPhone is locked to) is inserted, even though a SIM card from a different GSM provider is inserted. To do this and unlock your iPhone, first turn off your iPhone, and then remove its SIM card tray. Now take a look at the i3gSIM tool. You’ll notice a black chip that sticks out from the card in the top left corner of Figure 7-8. To get the tool to sandwich with your SIM card, you will need to cut a notch out of the SIM. The portion of the SIM card that you will be cutting out will not affect its performance in any way. A sharp knife such a razor blade is perfect for this job. Figure 7-9 shows a SIM card with the proper-sized notch cut out of it.

Figure 7-8. The i3gSIM unlocking tool

Notice the black chip in the top left that sticks out of the tool.

Figure 7-9. A SIM card with a notch cut out of it in the top right so that it can accommodate the i3gSIM unlocking tool

Once you’ve got your SIM card properly cut, get the i3gSIM tool, your SIM card, and the SIM card tray ready to put into your iPhone (Figure 7-10). Lay the i3gSIM tool on top of the SIM card so that the black chip is resting inside the notch, and place them into the SIM card tray, as in Figure 7-11.

190

iphone hacks

HACK # 7.03 Figure 7-10. SIM card tray, notched SIM card, and i3gSIM unlocking tool (left to right)

Figure 7-11. SIM card and i3gSIM tool

Now just slide the SIM card tray back into your iPhone, and turn it on. Once it’s started up, the carrier name at the top left of the screen will change to the name of the SIM card’s provider, as shown in Figure 7-12.

Figure 7-12. An iPhone using the i3gSIM unlocking tool. Notice how the carrier name at the top left has changed to T-Mobile!

chapter 07 - Unlock Your iPhone with a SIM Hack

191

Vendors and Caveats There are drawbacks to these solutions. Because they are hacking the phone+network combination, instead of the phone alone, there can be poor implementations: • •

Some cards work only with 2G (not 3G) networks. Some cards get banned from the cell network.

The reason for cell phone banning is that the hacks used violate network policies by looking like a “cloned” SIM card, which is a common method of stealing cell service. Even though the only SIM being “cloned” is your own, in an extreme case, this could cause the SIM to be banned from the network, requiring another SIM. Despite these caveats, a unit purchased from a reputable vendor is very likely to work on the networks and firmware versions they specify, and many such products are in successful use. Also of note: • Several vendors (such as i3gSim and RebelSim) make cards that do not require any SIMtrimming, by moving the microcontroller or producing custom trays for the phone. • Most vendors recommend that you put tape on your SIM card as a ripcord so that you can pull it out later. The small force exerted by the paperclip in the hole is insufficient to push out the wedged pair of cards. A few vendors are active in the iPhone unlocking market and update their products frequently to deal with new firmware. They all have a mysterious quality to them—no mailing address, all communication through the website—but perhaps this is to be expected of gray market phone hacking vendors. You should definitely check the community sites [Hack #2.06] and check references—and verify phone compatibility—before you send your money. These vendors are: www.any-network.com www.iphone-sim-unlock.com www.i3gsim.com www.rebelsimcard.com It’s worth noting that companies like www.yessim.com and www.rebelsimcard.com provide the programming tools (Figure 7-13) and bulk sets of 3G cards (in case you’re running a mobile phone unlock shop) and even lets you private-label your SIM sandwiches, in case you’re the entrepreneurial type. The programming tool lets you specify what network you want it to spoof for your phone (which varies by country) so that you can log onto the cell network successfully with your iPhone.

Figure 7-13. Yessim programming tool for 3G SIM

192

iphone hacks

HACK # 7.04

Hack 7.04:

Configure Your iPhone After Unlocking

Because Apple didn’t intend for the iPhone to be used with alternative mobile carriers, some of its functions may not work correctly after you finish an unlock. Luckily, you can fix them and get your iPhone working like it should. Fix Cellular Data Settings Once you’ve unlocked your phone via any of the methods described in previous hack, phone calls should work, but your cellular networking may not. On the first-generation iPhone with 1.x.x firmware, this was easy to do via Settings→Network→EDGE Settings (Figure 7-14). Nowadays, with 2.x firmware and 3G phones, it’s just a little bit harder.

Figure 7-14. Edge settings

There are just a few steps to fixing your networking:

1. 2.

Find out the Access Point Name (APN), username, and password for your network. Enter this data in the phone manually with a configuration utility or with a downloaded carrier bundle.

Step 1: Learn your APN. Find out the APN, username, and password for the network you want to connect to. You can find these settings by calling your carrier or looking online. A list of common APNs by carrier can usually be found on popular iPhone or BlackBerry forums such as www.pinstack.com/carrier_settings_ apn_gateway.html. Step 2: Edit your APN settings. With the information, you can edit the settings on your phone. To accomplish this you can either enable APN editing, use the iPhone Configuration Utility, or download a carrier pack from Cydia. Enable APN editing on the iPhone On older firmware, you could go to Settings→General→Network, but this does not work on 2.x firmware. To reenable this feature, you’ll need to edit the binary carrier.plist [Hack #11.02] corresponding to your carrier. Find the file /System/Library/Carrier Bundles/

where is the carrier for your SIM card (Figure 7-15). chapter 07 - Configure Your iPhone After Unlocking

193

Figure 7-15. Carriers

If you’re on a Mac, you can mount your iPhone with AFP [Hack #9.06] and double-click the .plist file to edit it (Figure 7-16).

Figure 7-16. Editing the carrier plist

Add the following text (if you’re editing the plist as a text file) or add the following key as a boolean (Figure 7-17):

AllowEDGEEditing <true/>

194

iphone hacks

HACK # 7.04 Figure 7-17. Setting AllowEDGEEditing to true

Now, the settings for that carrier will be editable in Settings→General→Network→Cellular Data Network (Figure 7-18).

Figure 7-18. Editable carrier settings

iPhone Configuration Utility If you have an Apple-unlocked phone [Hack #7.01] on 2.x firmware, you can also use the iPhone Configuration Utility (Figure 7-19) from www.apple.com/support/iphone/enterprise to create a profile—an XML file with the needed settings—that you email to your iPhone. You can find versions here: http://support.apple.com/downloads/iPhone_Configuration_Utility_1_1_for_Windows http://support.apple.com/downloads/iPhone_Configuration_Utility_1_1_for_Mac_OS_X Once you get it running, you’ll need to connect your phone, create a new configuration profile, and enter some information about it (Figure 7-19).

chapter 07 - Configure Your iPhone After Unlocking

195

Figure 7-19. iPhone Configuration Utility

The network settings are found under the Advanced tab. As an example, we’ll enter T-Mobile’s APN wap.voicestream.com, and enter guest for both username and password (Figure 7-20).

Figure 7-20. The Advanced tab

Once you’ve set all this and exported it, you’ll have a .plist file [Hack #11.02] that looks like Figure 7-21.

PayloadContent <array> PayloadContent <array>

196

iphone hacks

HACK # 7.04

DefaultsData apns <array> apn <string>wap.voicestream.com password Z3Vlc3Q= username <string>guest DefaultsDomainName<string>com.apple.managedCarrier PayloadDescription <string>Provides customization of carrier Access Point Name. PayloadDisplayName <string>Advanced Settings PayloadIdentifier <string>com.tmobile.iphone.apn PayloadOrganization <string> PayloadType <string>com.apple.apn.managed PayloadUUID <string>E5B5A7BA-2AB1-4946-899E-B39E318510B2 PayloadVersion 1
PayloadDescription <string>This is APN settings for my T-Mobile connec-tion. PayloadDisplayName <string>APN for T-Mobile PayloadIdentifier <string>com.tmobile.iphone PayloadOrganization <string> PayloadType <string>Configuration PayloadUUID <string>A339F026-0C7A-4B2F-9A97-25E62FF76C53 PayloadVersion 1
chapter 07 - Configure Your iPhone After Unlocking

197

Figure 7-21. Exported network settings

Email this file to your iPhone and open it on the iPhone. Click the attachment and you’ll see the screen shown in Figure 7-22.

Figure 7-22. Installing a profile

Download a Carrier Bundle from Cydia A simple way to get carrier bundles for some popular carriers is via Cydia. Search for the word “bundle,” or the name of your carrier, and you will get a list of carriers (Figure 7-23). You may need to add some sources [Hack #1.04] to find additional bundles.

198

iphone hacks

HACK # 7.04 Figure 7-23. Downloading carrier bundles

One More Thing: YouTube Fix On some phones where YouTube has not been “activated,” it will give an error message and not function after being unlocked on another carrier. If you can’t seem to get YouTube to connect, there is a straightforward fix for this:

1. 2.

3. 4. 5. 6. 7.

Download Pwnage or Winpwn. If you used these to do a software unlock, you should already have them. If you are doing a new unlock, you can simply check the “Activate YouTube” option when you create the image. With Pwnage, you will find the necessary files by viewing package contents on PwnageTool.app, then going to PwnageTool.app/Contents/Resources/CustomPackages/ YoutubeActivation.bundle, and viewing package contents again. On Winpwn look in /Program files/Winpwn/bundles/YouTubeActivation.tar. Extract the three files: data_ark.plist, device_ private_key.pem, and device_public_key.pem. Put the files in /private/var/root/Library/Lockdown [Hack #1.05], replacing the files that are there. Change the ownership and permission of the files [Hack #9.04] at the command line: chmod to owner=root, group=wheel, permissions = 0644. Create a folder called activation_records in /private/var/root/Library/Lockdown/ if one does not already exist. If there is a folder called pair_records in /private/var/root/Library/Lockdown/, delete its contents. Reboot the iPhone, connect to a Wi-Fi network, and try out YouTube. It should now work.

With EDGE and YouTube properly working, your unlocked iPhone should be as good as new.

chapter 07 - Configure Your iPhone After Unlocking

199

08

Customization People like to personalize and customize their phones. The multibillion-dollar ringtone market is a testament to that fact. And although Apple has provided a few ways to rearrange icons and change a background picture, there are dozens of other aspects of the phone that people want to change—but ordinarily can’t. The simplest example is ringtones. Although you can make ringtones out of any song you’ve bought online, iTunes doesn’t provide a way to make them with the songs you already have. With the techniques described in this chapter, that’s easy to remedy. System-wide skinning, system sounds, boot screens, and even the words that your iPhone recognizes are all susceptible to change once you know how. And if you want, you can even go beyond software and make skin-deep changes to the color scheme of your phone. With almost 10 million iPhones sold at the time of this writing, you may no longer feel unique in having an iPhone. In some circles, just about everyone has one. But before mourning your complete loss of social cachet, it’s worth noting that according to Gartner Research (www.gartner.com/it/ page.jsp?id=612207), about a billion mobile phones ship each year. If you’re still feeling like a lemming after that reassurance, remember that performing the hacks in this chapter will help you ensure that your iPhone is unequivocally one of a kind.

Hack 8.01:

Add Custom Ringtones to Your iPhone

The iPhone comes with several preinstalled ringtones when you first purchase it, but if that isn’t enough, there are a couple ways in which you can add your own ringtones. Apple has provided a method for creating ringtones from songs in iTunes to sync to your iPhone. However, the downside of using iTunes is that you can create ringtones only from songs that you’ve purchased from the iTunes store. Furthermore, after you create the ringtone, you have to purchase it again from the iTunes store. You have to purchase the same song twice! If you would rather customize your ringtone for free, and be able to choose any sound you want, then you’re in luck. There are several different ways to go about doing this.

200

iphone hacks

HACK # 8.01

Custom Ringtones via iTunes Although iTunes may be infamous for trying to sell you ringtones for your iPhone, it can also be used as a tool to create custom ringtones from songs in the music library:

1. 2. 3. 4. 5. 6. 7.

Open the Preferences menu on iTunes, click the Advanced tab, and click the Importing subtab. Make sure that the Import Using box is set to AAC Encoder, as in Figure 8-1. Close the Preferences menu, right-click the song in your iTunes library that you’d like to make a ringtone from, and select Get Info from the context menu, as shown in Figure 8-2. Click on the Options tab, check the Start and Stop Time boxes, and enter custom times, as in Figure 8-3. Once you have custom start and stop times, click OK at the bottom right to close the song info window. Right-click the song again, and select Convert Selection to AAC, as in Figure 8-4. iTunes will convert it, and place the custom song back in your music library, as in Figure 8-5. Right click the newly created clip and click “Show in Windows Explorer/Finder.” Drag this file to the desktop and delete the entry from your iTunes Library. Change the .m4a file extension to .m4r. Double click on the renamed song, and iTunes will automatically place it in the Ringtones library, as in Figure 8-6. Now the ringtone can be synced to your iPhone (Figure 8-7).

Figure 8-1. Setting the import preferences to use AAC Encoder

chapter 08 - Add Custom Ringtones to Your iPhone

201

Figure 8-2. Selecting Get Info

Figure 8-3. Setting custom start and stop times

Figure 8-4. Converting the song to AAC format

202

iphone hacks

HACK # 8.01 Figure 8-5. After converting, the custom song will appear in the library

Figure 8-6. The renamed .m4r song shows up in the ringtones library

Figure 8-7. Syncing the custom ringtone

chapter 08 - Add Custom Ringtones to Your iPhone

203

Custom Ringtones via Other Applications GarageBand If you’re the creative type, you can make tracks in GarageBand and import them directly to iTunes as ringtones.

1. 2. 3. 4.

Open GarageBand and either compose a song or open one you’ve already made. Select Share→Send Ringtone to iTunes. A dialog box will tell you that you need to select a looping portion of your song, less than 40 seconds, and will show you the cycle button that you need to press (Figure 8-8). Press the Cycle Region button, which lets you highlight a section of the song to loop above your track. Pick a section of up to 40 seconds to use as a looping ringtone (Figure 8-9). Select Share→Send Ringtone to iTunes again. Your song will appear on the ringtone list and, if you’ve set iTunes up to sync ringtones, it will be sent to your iPhone the next time you sync.

You don’t have to compose a song in GarageBand for this to work—you could drop any unprotected music file or audio clip in GarageBand and turn it into a ringtone.

Figure 8-8. Send Ringtone to iTunes

Figure 8-9. Making a ringtone with GarageBand

204

iphone hacks

HACK # 8.01

The App If you want a faster, easier method of transferring ringtones, try iToner, available from www.ambrosiasw.com/utilities/iToner (Figure 8-10). iToner is designed to put sound files onto the iPhone for use as ringtones. It has a very simple-to-use interface and reasonable price tag (a $15 one-time fee can end up costing you less than paying $1–$3 per song).

1. 2. 3.

Make sure that your iPhone is plugged into your computer. Download, install, and run iToner. A window resembling an iPhone will pop up. Drag and drop the files you want to add onto the window to add them to the list. Press the Sync button on the bottom of the window. iToner will add the files on the list to your phone’s ringtone menu.

And you’re done. iToner is easily worth it if you want to halve the number of steps and quarter the amount of time necessary to put ringtones on your phone from the alternative method presented earlier.

Figure 8-10. iToner

If iToner isn’t your thing, there’s iPhoneRingToneMaker (www.efksoft.com/products/ iphoneringtonemaker/index.htm). This app also does MP3s, WAVs, and OGGs. It also works on Windows.

The iPhone App iDrum [Hack #10.01] allows you to create ringtones based on the iDrum songs you make. All you need is the iDrum Ringtone Sync app from www.izotope.com/products/audio/idrum/iphone, and you’re golden. Run iDrum on your phone, and iDrum Ringtone Sync on your computer. Follow the instructions on iDrum Ringtone Sync, and before you know it, your handcrafted tunes will be ripped into iTunes and available to sync as ringtones onto your phone.

The Directory If you’ve SSHed into your iPhone [Hack #9.04] or have an AFP connection on your phone [Hack #1.05], then this hack will be the simplest ever. If for some reason you can’t get the iTunes hack at the top of this chapter working, try this method. Follow the steps as listed previously, but once you have your ringtone converted to AAC and chapter 08 - Add Custom Ringtones to Your iPhone

205

renamed as a .m4r, navigate to /var/stash/Ringtones/ on your iPhone and drop the file straight in there. It will appear on the list on your phone with all the standard ringtones, no restart or sync needed. Whether you’re using a Mac or a PC, there is always a custom ringtone solution that doesn’t rely on the expensive iTunes Store method. What will you do with all the money you save?

Hack 8.02:

Skin Your iPhone and Change System Sounds

You can change the skin of your iPhone in nearly limitless ways using WinterBoard. The iPhone has a very carefully designed user interface, handcrafted to the last pixel by designers at Apple. Though that’s admirable, it does nothing to reduce people’s urge to customize every aspect of their GUI with their own graphics. On a jailbroken phone, this is possible.

Introduction to Themes On its main screen, the iPhone runs an application called SpringBoard (Figure 8-11), which is the global launcher for applications. It can be thought of as a stripped-down mobile version of similar tools such as the Finder in OS X, the file browsers on Gnome and KDE in Linux, or Explorer in Windows.

Figure 8-11. The SpringBoard

The first approach to skinning was simply to find where all the images were stored and manually replace them. Eventually the paths for all the images contained in a skin (the black “wallpaper,” the application icons, etc.) were discovered, and the people rejoiced and made full collections of skins to replace these images. This functionality was soon simplified into an application named SummerBoard. SummerBoard—whose name is based on the seasonal definition of Spring (get it?)—allowed users to install skin packages from Installer and toggle them at will. Its power was

206

iphone hacks

HACK # 8.02 limited, however, and there were several icons that it was not programmed to change. Some examples are the signal and Wi-Fi indicators, the battery icon, and SMS chat bubbles. Other applications such as Customize were available to change these. With the arrival of Version 2.0 firmware, the closed source and rarely updated SummerBoard was usurped by WinterBoard (Figure 8-12), and there was again much rejoicing (and much skinning, of course).

Figure 8-12. Left: A reskinned SpringBoard with the KillSignCarbonRed skin by KillSign. Right: SMS screen reskinned with the Abstract Racing Stripe skin by poetic_folly and Chromium Keyboard skin by Allen from planet-iphones.com.

Using WinterBoard WinterBoard can be found on Cydia [Hack #1.04], and a wealth of skins can be found there too. We mean it: there are hundreds. As you scour the categories on Cydia and accumulate skins, they will appear on the WinterBoard menu (Figure 8-13). See Figure 8-14 for an example of what skins can do for your device.

Figure 8-13. The WinterBoard menu with some skins downloaded

chapter 08 - Skin Your iPhone and Change System Sounds

207

A checkmark indicates the package that’s been chosen to skin your phone (Figure 8-14). Figure 8-14. A richly skinned phone, with an animated background

WinterBoard skins “stack,” so that the highest skin in the stack will override any icon below it. Thus, if there are smaller additions you want to install over a larger skin, arrange them so that the smaller packages are above the larger packages (incidental icons higher on the list than full skins). This makes them replace the redundant images in the larger package (Figure 8-15).

Figure 8-15. The skinned signal and Wi-Fi bars: no longer the package defaults

WinterBoard can also support sound packages, allowing you to change various UI sounds. It’s hard to take a screenshot of those, however, so you’ll have to take my word for it!

Understanding WinterBoard WinterBoard works by having named folders for each theme, containing picture and/or sound files that are used to replace files located elsewhere while the theme is enabled. Theme creation consists of making a folder in /Library/Themes/, named whatever you want the theme to be called, then placing files in this folder with specific names and subdirectories in order to replace other files. The folder /Library/Themes/ is actually a link to /var/stash/Themes. WA77b5/. If for some reason you can’t work with /Library/Themes/, use /var/stash/Themes. WA77b5/ instead.

208

iphone hacks

HACK # 8.02

dd

If you download an old theme that is for SummerBoard and not WinterBoard, it will still work, but the files will be located in /var/mobile/Library/SummerBoard/Themes/.

Ideally, you should give your folder a .theme file extension (i.e., /mycooltheme.theme/). You can still work with it as a folder, but it’ll be more of a tidy package and easier to identify. Now that you know where the themes go, what sorts of things can you put in them? •

Themes/themename/Wallpaper.png will change the wallpaper on your SpringBoard that sits behind the applications. Themes/themename/Icons/ is an easy way to change the images used to represent applications. Place an appropriately sized .png named after the application (e.g., WinterBoard. png or App Store.png) in it. This is useful if your theme entirely remakes the color scheme or icon style of the interface, and the standard candy-colored rounded square icons of most applications don’t fit any longer.

To change deeper, more interesting images, you’ll need to make folders for each application based on its bundle name. This is a string in the format com.authorname.appname. For example, com.apple. calculator is the bundle name of the default Apple calculator application. Therefore, if you want to make a custom skin for the calculator, you’ll need to make a folder called Themes/themename/ com.apple.calculator and put files in it corresponding to the files in the application itself. How do you find out the names of the files you want to replace, as well as the package name? Go to /Applications/ (or /var/mobile/Applications/, for App Store apps) on the iPhone, and open the .app package like a folder. (On a Mac, control-click for View Package Contents.) This will have all the images in the proper subdirectories that you need to mirror in your theme (Figure 8-16). Any image you put in your theme that matches an image in the application will take precedence and replace it while your theme is enabled. To find out the bundle name, you’ll need to open the Info.plist file and find the entry for CFBundleIdentifier. It will be in the com.authorname.appname format. For more information on plists, see [Hack #11.02].

Figure 8-16. The calculator buttons in file format within the app itself

One common application you’ll want to edit is the SpringBoard itself. This is what you want to work with if you want to change the icons on the top bar, the dock background, and so on.

chapter 08 - Skin Your iPhone and Change System Sounds

209

Changing Sound Files These files are AIFF format audio files with the extension .caf instead of .aif. To put sound files in a theme, put them in Themes/themename/UISounds/ with a subdirectory structure matching that of /System/Library/Audio/UISounds/.

Changing Carrier Logos Sometimes the cleverest statements are made with hacked carrier logos. Instead of a boring text string, replace the carrier’s name with their iconic logo. Or change it to something from left field (Figure 8-17).

Figure 8-17. Live in denial or live in the past with a hacked carrier logo

To change your carrier logo, the directories you’ll need to know are /System/Library/Carrier Bundles/ and Themes/themename/Bundles/. The first one is the directory where all the bundles containing pictures and other data for the different available carriers are located. The second directory is where you must put the directory corresponding to the carrier you’d like to change. For example, /Bundles/com.apple.ATT_US/ is where AT&T modifications go. Just like for applications, you’ll need to find the Info.plist in the bundle to see what to name your folder. The folder structure for the LA Cellular logo theme is shown in Figure 8-18.

Figure 8-18. /Bundles/com.apple.ATT_US/ is where AT&T modifications go

FSO_CARRIER_xxxxx.png is the “light” version of the image, for use when the top bar is dark, that is, on the SpringBoard. Default_CARRIER_xxxxx.png is the “dark” version, with black text for when the top bar is silver, that is, in an application. The other files are actually somewhat important to the carrier’s operation, so you probably don’t want to try to include those in your theme.

And More If you find a theme that does something different than what is already described in this hack, you can always do an autopsy on the theme directory and see what it did. It may involve custom files or special .plist editing [Hack #11.02]. For more insight and advanced feature details, check out www.saurik.com/id/9 for a full-featured rundown on more to do with WinterBoard.

210

iphone hacks

HACK # 8.03

Hack 8.03:

Change Your Boot Screen

Don’t forget the boot screen and restore logos when you’re customizing your device. You can use WinterBoard [Hack #8.02] to change practically every image and sound on your phone. Everything on your phone reminds everyone how much you like the Raiders/World of Warcraft/the color blue/Star Wars/trucks, except for when you restart your phone (Figure 8-19). Unfortunately, the graphics for the boot screen are not stored on the filesystem and aren’t susceptible to mere file replacement. This hack will show you how to finish customizing your iPhone’s graphics.

Figure 8-19. The ubiquitous boot screen

There are much more interesting graphics that you could display when booting your phone, and several ways to achieve this.

Via Pwnage The simplest way is to do it is when you first hack your phone. When using the PwnageTool [Hack #1.03], you’ll want to be in expert mode. After choosing a package to modify, click the Custom Logos button (Figure 8-20).

chapter 08 - Change Your Boot Screen

211

Figure 8-20. The Pwnage Custom Logos screen

The image on the left represents what your “silver apple” will become, and the one on the right represents what the “Connect to iTunes” screen will be, that is, the one that appears on a phone in Recovery mode. You can find, create, or edit images to fit the dimensions specified in the app, then select them for your custom restore package. Whenever you restore your phone with that package, the images that you selected will be used for your boot and/or restore logos.

Via the LogoMe App If you’ve already hacked your phone and don’t want to re-restore and lose your changes, there is another procedure that you can use. The application LogoMe (Figure 8-21) allows you to change your boot screen without restoring your phone.

Figure 8-21. LogoMe

When you start LogoMe, it will download a portion of unmodified firmware in order to edit and reflash it. Find a .png somewhere online that you want to use as your boot screen, type the URL 212

iphone hacks

HACK # 8.04 into the next screen in LogoMe, and download it. On the Install Logo tab, you can preview the image (Figure 8-22) to make sure that it’s downloaded properly, and finally install it. Your boot screen is changed quickly and simply.

Figure 8-22. Image from eff.org

Hack 8.04:

Enhance Autocorrection with Address Book Entries

Teach your iPhone your favorite words. The iPhone and iPod touch’s autocorrection can be very helpful when typing messages. It reduces the amount of legitimate typos and grammatical errors (Figure 8-23).

Figure 8-23. Thank you, iPhone/iPod!

Problems ensue when you try to use words that are outside the built-in dictionary (Figure 8-24).

Figure 8-24. No thank you, iPhone/iPod!

Supposedly the iPhone will learn after three instances of your correcting its correction (by tapping the x on the autocorrect popup), but this does not always work, for some mysterious reason. The most noticeable issue is with swear words. The iPhone assumes that you want to say, “I’m not taking your shot anymore, it ducking posses me off,” but what does that even mean? Are we playing basketball? Fortunately, there’s a more reliable, visible way to make your device remember useful words. If you put these words in an address book entry, the iPhone will give them linguistic priority (Figure 8-25). chapter 08 - Enhance Autocorrection with Address Book Entries

213

Figure 8-25. Your words may vary

Put the words you want to use into a custom address book entry in the Note section. You could also put these in existing address book entries, if you want to put obscene secret messages that (hopefully) only you know about on your family’s and/or co-workers’ entries.

Hack 8.05:

Skin Your iPhone Externally

ColorWare can color-code your iPhone to fit your color cravings. Setting the Scene You’ve made your own custom skin and boot screen, but it bothers you that your iPhone isn’t personalized at all when it’s lying there with the screen off (and you’ve tried custom cases; they aren’t your thing). If only that dull metal/shiny white/shiny black back of your phone could be made more interesting and colorful. ColorWare (www.colorwarepc.com; see Figure 8-26) is a company that has been doing colorization of various devices since 2000.

Figure 8-26. ColorWare

214

iphone hacks

HACK # 8.06 They can help you paint the exterior of your iPhone to fit your wishes. Maybe you miss your old U2 edition iPod, and wish you could have a red-tinted U.S. edition U2 iPhone (Figure 8-27)?

Figure 8-27. U2 2.0

Or a slick blue iPod touch, with a dock and headphones to go with it (Figure 8-28)?

Figure 8-28. Color me blue

It costs a pretty penny, but it could very well be worth it to add that extra personalization you crave.

Hack 8.06:

Hide Unwanted Applications

BossPrefs and an app launcher will keep your apps out of sight, but there if you need them. Are you one of the many iPhone or iPod touch users for whom the Stocks app is pointless? Do you find the Notes app so useless as to be offensive to your sight? Are there some apps that you simply wouldn’t like others to see or mess with? You’ve tried to throw your unsightly apps on to another SpringBoard page, but they’re still there, wasting real estate. And you don’t want to delete them, because you know at some point they might be useful—and if they’re gone, you’re left kicking yourself.

chapter 08 - Hide Unwanted Applications

215

Your solution is simple: BossPrefs, available from Cydia. It has an app that used to be known as Poof! integrated into it. What does Poof! do? It gives you a list of toggle switches (Figure 8-29) for all the apps currently on your phone (from the App Store or elsewhere). If you don’t want to see an app, just set the slider next to it to Off, and it will vanish from the SpringBoard. If you change your mind, you can flip it to On. There when you want it; not there when you don’t—simple as that.

Figure 8-29. Hide iTunes to prevent impulse buying; hide Vonagent to prevent voicemail snooping, and so on

Now, if you just don’t want it on the SpringBoard, but want to be able to access it more quickly than it would take to constantly rinse and repeat the previous instructions, all you need is an app launcher...app. Several come up when you type “launcher” into the search bar in Cydia, and they should all work equally well. Here we use AppFlow by Erica Sadun as an example, because it is pretty. These launchers will indiscriminately list all the apps on your phone, hidden or not (Figure 8-30). You can tap any of them and get going quickly and easily. AppFlow even features a landscape Cover Flow mode (Figure 8-31).

Figure 8-30. Keep apps out of sight until you need them

216

iphone hacks

HACK # 8.06 Figure 8-31. Stocks, how are you doing? I haven’t seen you in a while.

chapter 08 - Hide Unwanted Applications

217

09

network hacks The iPhone and iPod touch both shine at networking. Because there’s Unix inside them, there’s an almost limitless supply of open source networking software available to recompile for use on the iPhone. Shortly after the iPhone was jailbroken and development tools were developed for it, all the usual suspects—web servers, file servers, scripting languages—were ported over to the iPhone. After Apple opened up the iPhone to developers, some tools appeared in the App Store as well. To an end user, this may not seem like much. But to power users and developers, the iPhone is a tool of unparalleled flexibility. You can SSH into your servers. You can use it as a remote control for your media center—or your desktop PC. You can surf the Web with remarkable fidelity, download files, upload files, and generally do anything that you could want to with a desktop computer running Mac OS X, Windows, or Linux. This chapter presents a sampling of some useful networking features of the iPhone and iPod touch. Many of the staple applications for server administration are available in the App Store, and even more are available for a jailbroken phone. Because of ongoing development, new network apps appear constantly, so keep searching for your favorite protocol or utility in Cydia and the App Store.

Hack 9.01:

Use Your iPhone or iPod touch as a Trackpad

Upgrade your several-hundred-dollar device to a several-hundreddollar wireless trackpad. Many people connect computers to their flat-screen TVs in order to watch movies. But it’s not always that easy to remotely control media player software that was designed to be used with a mouse. For instance, if you have a Mac Mini hooked up to your television, the Apple Remote won’t control VLC, QuickTime, or the DivX player. A Bluetooth mouse won’t work well on the arm of your couch, and a wireless keyboard with integrated trackpad is a pretty bulky remote. What device do you own that can talk to other computers, and has a touch screen? Hmm... There are several apps at several different price points that allow your iPhone and iPod touch to control your PC or Mac. The price point ranges from free to $9.99. Let’s take a look at the free RemotePad to get a feel for how these applications work.

218

iphone hacks

HACK # 9.01

RemotePad (http://tenjin.ics.es.osaka-u.ac.jp/RemotePad) is your free solution. It comes in two parts: a desktop server and an App Store app. With these two parts, it takes mere moments to set up. Make sure that your two devices are in the same wireless network. Start the server on the desktop, and the app on the iPhone/iPod. Your computer’s name should show up on your device (Figure 9-1). Tap it, and you should be good to go. Your new screen will be black with buttons, and you can start trackpadding around your computer (Figure 9-2). You’ll have to try it for yourself to see it in action, as a screenshot could never do it justice.

Figure 9-1. The server selection screen

Figure 9-2. Making a real connection

The other apps will have different layouts and features: look for them in the App Store or Cydia and give them a try if RemotePad doesn’t cut it.

chapter 09 - Use Your iPhone or iPod touch as a Trackpad

219

Hack 9.02:

Control Your Desktop or Laptop with Your iPhone or iPod touch Control your whole PC from your iPhone or iPod touch. Are all the remotes [Hack #4.03], [Hack #10.06], [Hack #12.23] in this book not enough? Is something not covered? With this hack you can type responses to instant messages, open new applications, check file transfer status, and start and stop your media player—the possibilities are endless! First, install a server on your desktop PC, if you haven’t already done so. RealVNC is a good, free server for Windows. For Mac you can either use Vine (www.redstonesoftware.com), or you can go into your Sharing settings in System Preferences and enable VNC, as shown in Figure 9-3.

Figure 9-3. The easy way to VNC into your Mac

Before firmware 2.0 [Hack #1.02], there were a number of jailbroken VNC clients for the iPhone. Now that we have Mocha VNC (Figure 9-4) in the App Store, its predecessors have vanished.

Figure 9-4. Mocha VNC controlling a Mac

To use VNC, install one of the servers listed earlier onto your machine (or configure Remote Desktop, also as described previously). Then configure and launch the server, and enter your desktop’s internal IP into Mocha VNC. You can zoom using two-finger multitouch, and control your computer just as if you were there! For Windows Remote Desktop users there is an app called Remote Desktop (Figure 9-5). It works essentially like Mocha VNC, but with special support for Windows Remote Desktop.

220

iphone hacks

HACK # 9.03 Figure 9-5. Remote Desktop

Another solution, if you run software from LogMeIn, is their release of LogMeIn Ignition (https:// secure.logmein.com/products/ignition/iphone), a version of their client software for the iPhone (Figure 9-6).

Figure 9-6. LogMeIn Ignition

Hack 9.03:

Control Your iPhone or iPod touch with Your Desktop or Laptop You can control a jailbroken phone right from your desktop. Reaffirming the fact that the strong can control the weak, here comes the jailbroken app Veency. Veency is a VNC server for your iPhone/iPod touch, as opposed to Mocha VNC, which is a VNC client. What does that mean for you? It means you can do something akin to Figure 9-7.

Figure 9-7. That is not an iTunes control widget—that is an iPhone!

chapter 09 - Control Your iPhone or iPod touch with Your Desktop or Laptop

221

Just download a client onto your computer, like RealVNC’s VNCViewer for Windows or Chicken of the VNC for Mac. Put your computer and device on the same network, and put your iPhone/ iPod’s local IP into your desktop’s VNC client. As there is no password option yet, a confirmation screen will show up on your device (Figure 9-8). An iPhone-sized screen will pop up and you will be in control.

Figure 9-8. Big Brother computer knows what’s best

Left-click taps, right-click (Control-click on Macs) presses the Home button, and middle-click locks the phone. If you want to take this and [Hack #9.02] to create an infinite loop of remote control, that’s your decision—please just don’t make the universe swallow itself.

Quick hack Save Time When Typing in the Terminal Tab autocomplete is performed by entering “Control+I” while in the mobile terminal. Because there is no Control key, the large dot symbol is used instead. To enter a dot, select “.?123”, then press “#+=”. The dot should be on the right side of the keyboard, above the backspace.

222

iphone hacks

Hack 9.04:

Connect to Your iPhone with a Secure Shell (SSH) Terminal Program You can use a terminal program to connect to the iPhone, copy files to and from it, manipulate the filesystem, and run programs. Contrary to the corny virtual-reality-in-cyberspace-VR-glove user interfaces depicted in contemporary Hollywood movies, most “hacking” is actually done with text commands on a simple monochrome screen. As it turns out, a lot of system administration is done this way, too. Secure Shell, or SSH, is a network protocol that creates a secure connection between two computers and allows them to exchange data. It has replaced the venerable but insecure Telnet, and is the universal way to “log on” to a Unix or Linux machine remotely. Although this book tries to provide links to GUI-based “hacking” tools whenever available, the reality is that almost every hack in this book was initially performed by SSHing (that’s the verb form) into the iPhone and executing the necessary commands. In fact, if you aren’t a programmer, but you like to try out the most bleeding-edge hacks, you’ll need to know how to use a terminal.

HACK # 9.04

Installing an SSH Server There have been various versions of SSH installed by the various jailbreaking tools on the iPhone, but as of this writing the stable SSH is provided by Cydia. When you run Cydia, you can find SSH on the main screen, or you can search for OpenSSH and install it (Figure 9-9).

Figure 9-9. Installing SSH

The SSH server works only over a Wi-Fi network. It probably would work over 3G, but usually the network operator blocks incoming services and does not provide mobile phones with a public IP address. Usually the iPhone connects to a Wi-Fi network and gets a dynamic (temporary) IP address. To SSH into the phone, you’ll need to get a terminal program, and you’ll need to know your iPhone’s IP address. You can find the IP address by going to Settings→General→Network→Wi-Fi and then clicking the arrow next to the network you’re connected to. You’ll see DHCP selected in blue, and your IP address (Figure 9-10).

Figure 9-10. Finding out your dynamic IP address

If you find yourself connecting to your iPhone a lot, looking up the IP address all the time will become annoying, so you may want to set a static (unchanging) IP address for connection to your Wi-Fi network. To do this, note down the information for your DHCP address, then go to the Static tab and enter it all in, but set the last digit of the IP address to something that you can remember (Figure 9-11). Your iPhone will remember this IP address and will use it whenever it connects to this Wi-Fi network again (i.e., at your home or work).

chapter 09 - Connect to Your iPhone with a Secure Shell (SSH) Terminal Program

223

Figure 9-11. Setting a static IP

Whenever you use SSH to connect to your iPhone, you’ll be required to enter a username and firmware-specific password. Although late-model firmware added a second user, mobile, the superuser, root, has access to the entire filesystem and can change things more easily: • • •

User name: root Password for firmware 1.0.2 and earlier: dottie Password for firmware 1.1.1 to 2.2: alpine

Once you have SSH installed and know your IP address, the next step is to get connected.

SSH Client Software for Windows If you’re a Windows user, there are two main programs that you should have on your computer to connect via SSH with your iPhone: PuTTY and WinSCP. PuTTY is a terminal client for PCs that allows you to connect to SSH servers and enter commands. It can be downloaded from www.chiark.greenend.org.uk/~sgtatham/putty. When you start the program, you’ll see a configuration window (Figure 9-12). Enter your iPhone’s IP address in the Host Name box, choose SSH for the Connection type, enter 22 in the Port box, and then click Open. When you connect to your iPhone for the first time, you’ll be asked to “permanently add the RSA key fingerprint.” RSA is a method of encryption, and adding the fingerprint indicates that you trust the remote machine (your iPhone), so just select Yes (Figure 9-13). If you ever connect to a different machine with that same IP address with SSH, the program will let you know that the key has changed, as a safety precaution, so that you can verify which machine you’re connecting to. You may have to wait a while the first time you connect, while the iPhone generates an encryption key. A new black window will open, and prompt you to log in and enter a password. Type root as your login name, and use the appropriate password for your iPhone’s firmware (see the previous section). Upon entering the correct password, your session will start, and you can start typing commands (Figure 9-14).

224

iphone hacks

HACK # 9.04 Figure 9-12. PuTTY configuration

Figure 9-13. Accepting the host key

Figure 9-14. After login, you can enter terminal commands into PuTTY’s window

Now you’re connected to your iPhone and ready to type commands.

chapter 09 - Connect to Your iPhone with a Secure Shell (SSH) Terminal Program

225

WinSCP is SSH client that features a graphical user interface to the files on an SSH server. It can be downloaded from http://winscp.net. WinSCP functions similarly to file browsing programs such as iPhoneBrowser [Hack #1.05]. In addition to its file browsing capabilities, WinSCP also has PuTTY built in. When you start WinSCP, you’ll see the login window, as in Figure 9-15. Click New in the top-right corner, which produces a new window (Figure 9-16). Enter your iPhone’s IP address in the Host Name box, and enter 22 in the Port Number box. Enter the appropriate username/password combination, according to your firmware version (see the earlier section in this hack), and then click Login and type “yes” when prompted.

Figure 9-15. WinSCP login window

Figure 9-16. Connecting via WinSCP

A window will open displaying the /private/var/root/ directory of your iPhone on the right, as in Figure 9-17. You can navigate through your file directory, and upload and download any files to and from your iPhone. If you need to run terminal commands, just click the Commands tab at the top, as shown in Figure 9-18, and you can open PuTTY conveniently.

226

iphone hacks

HACK # 9.04 Figure 9-17. The /private/var/root/ directory of the iPhone is shown on the right side of the WinSCP window

Figure 9-18. Clicking on the Commands tab

SSH Client Software for Mac Users Mac computers feature a built-in SSH client that can be accessed by opening Terminal, which is found in Applications→Utilities→Terminal. In the Terminal window type ssh root@ followed immediately by your iPhone’s IP address, as shown in Figure 9-19. When you connect via SSH to your iPhone for the first time, you’ll be asked to permanently add the RSA key fingerprint. RSA is a method of encryption, and adding the fingerprint indicates that you trust the remote machine (your iPhone), so just select Yes. If you ever connect to a different machine with that same IP address with SSH, the program will let you know that the key has changed, as a safety precaution, so that you can verify which machine you’re connecting to. Once you log in, you can now enter commands.

chapter 09 - Connect to Your iPhone with a Secure Shell (SSH) Terminal Program

227

Figure 9-19. Connecting to the iPhone’s SSH server in Terminal

If you need a good SSH file browsing program, then Cyberduck is for you. It can be downloaded from http://cyberduck.ch. When you start the program, click Open Connection at the top left of the window. A new window like the one in Figure 9-20 will open. Select SFTP for the protocol, enter your iPhone’s IP address in the Server box, and enter the standard SSH login and password for your firmware version (see the earlier section in this hack). Finally, click Connect—Cyberduck will display your iPhone’s file directory so you can make any necessary changes, as shown in Figure 9-21.

Figure 9-20. Configuring the connection settings on Cyberduck

Figure 9-21. Browsing the iPhone’s file directory with Cyberduck

228

iphone hacks

HACK # 9.04

What Do I Do Now? If you’re new to Terminal, there are plenty of resources to help you learn the Unix shell on Mac OS X. If you’ve logged in to your iPhone in order to run through the steps of some online walkthrough, it’s worth learning a tiny bit about the shell—the text environment you’re logged into—so you can feel more comfortable with what you’re doing.

dd

For a gentle introduction to the Unix shell used by Mac OS X, see Learning Unix for Mac OS X Tiger, by Dave Taylor (O’Reilly).

A good online resource for learning the command line is http://linuxcommand.org/index.php. Linux, you say? Well, the command-line tools are pretty much equivalent across Unix and Unix-like machines.

Hacking the Hack: SSH with no passwords

find missing directories   and files A few commands will get you going: changes directory, so you can type, for instance, cd /var/

When you’re doing development work or copying files to and from your iPhone from a command line, it can get somewhat tiring typing in your passwords over and over. Especially when you’re developing on your computer using the toolchain [Hack #11.06] and testing on the phone, you probably want your make script to automatically copy the application you build over to the phone without demanding a password.

• cd

Another reason to eliminate the shell is scripting on the phone. If you want to write scripts to back up files to the Internet, i.e., to your web server, you’re going to need a secure channel between your iPhone and the server that doesn’t require passwords.

SSH is secure because it uses a pair of encryption keys, a public and a private one. Each key can decode data that is “locked” by the other key. Thus, to “pair” two computers, you need to create a pair of keys, put the public key on the destination computer, and keep the private key only on the source computer. To make this clearer: •

If you want to log into your iPhone from, say, your desktop, you create a private/public key pair on your desktop and copy the public key to your iPhone If you want to log into a server from your iPhone, you create a private/public key pair on the iPhone and copy the public key to the server

The following walkthroughs will show you how to do this: SSH with no passwords In this example, the author’s computer is dps17 (a 17" Mac Book Pro) and the author’s iPhone is dps-3G. Since my iPhone has been set to a static IP address I’m going to create an alias to it in /etc/hosts (Figure 9-22), which will allow me to access it by name. You can type in the bolded commands to duplicate the steps.

mobile/Media/

lists what files are there. pwd tells you what directory you are in. Several hacks in this book reference specific directories or files that need to be modified. However, depending on your phone’s firmware version, you may have a different directory structure. In this case, find the new directory by entering the following command in the mobile terminal, or an SSH session:

• ls

find / -name "

"

Make an alias and edit the file as shown in Figure 9-22: dps17-2:~ $ sudo pico /etc/hosts

chapter 09 - Connect to Your iPhone with a Secure Shell (SSH) Terminal Program

229

Figure 9-22. editing /etc/hosts

Ping the iPhone: dps17-2:~ $ ping iphone PING iphone (192.168.22.99): 56 data bytes 64 bytes from 192.168.22.99: icmp_seq=0 ttl=64 time=328.536 ms 64 bytes from 192.168.22.99: icmp_seq=1 ttl=64 time=85.387 ms ^C --- iphone ping statistics --2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max/stddev = 85.387/206.962/328.536/121.575 ms

To generate the private/public key pair on the computer: dps17-2:~ $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/dstolarz/.ssh/id_rsa): <press enter> Enter passphrase (empty for no passphrase): <press enter> Enter same passphrase again: <press enter> Your identification has been saved in /Users/dstolarz/.ssh/id_rsa. Your public key has been saved in /Users/dstolarz/.ssh/id_rsa.pub. The key fingerprint is: f1:d7:1a:aa:d9:f3:7c:1b:66:17:05:05:a7:ca:ce:90

The key's randomart image is: +--[ RSA 2048]----+ |

ooo|

| | | | | |

+ | .

. .| o o o

.|

S E = .. | * o

.|

. + + .|

|

+.. o.o |

|

o .oo... |

+-----------------+ dps17-2:~ dstolarz$ ssh root@iphone mkdir -p .ssh root@iphone's password: alpine

230

iphone hacks

HACK # 9.04 dps17-2:~ $ cat .ssh/id_rsa.pub | ssh root@iphone 'cat >> .ssh/authorized_keys' root@iphone's password: alpine dps17-2:~ $ ssh root@iphone dps-3G:~ root#

iPhone→server with no passwords In this example, the author’s computer is dps17 (a 17" MacBook Pro), and his iPhone is dps-3G. The following assumes that a user named iphonehacks exists on the server (perceptdev.com): Let’s test this new user. Here are the commands we typed from a Terminal on the iPhone, just to make sure we can actually connect from the iPhone: dps-3G:~ # ssh

The authenticity of host 'perceptdev.com (208.97.133.135)' can't be established. RSA key fingerprint is da:86:84:d0:c0:66:20:17:58:da:b8:86:a1:3b:1f:72. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'perceptdev.com,208.97.133.135' (RSA) to the list of known hosts. Password: Linux perceptdev 2.6.24.2-grsec-p4-peon-1.1.2-grsec #1 SMP Wed Feb 20 15:30:29 PST 2008 i686 GNU/Linux [perceptdev]$ exit logout Connection to perceptdev.com closed.

Our goal is to be able to upload files from the iPhone to the perceptdev.com shell account automatically from a script. First we log into the iPhone from the computer (you could do this from a Terminal on the iPhone, but it’s easier from a computer), then we create and copy our public key to perceptdev.com, and finally we log in without requiring a password. dps17:~ $ ssh root@iphone dps-3G:~ # ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/var/root/.ssh/id_rsa): <press enter> Enter passphrase (empty for no passphrase): <press enter> Enter same passphrase again: <press enter> Your identification has been saved in /var/root/.ssh/id_rsa. Your public key has been saved in /var/root/.ssh/id_rsa.pub. The key fingerprint is: e6:68:35:95:ac:7e:d0:e4:27:5a:08:e2:01:4b:1b:59 root@dps-3G The key's randomart image is: +--[ RSA 2048]----+ |

+oE

|

| ..= | | |

|

=

|

o o . . o . B .

S = .

|

* = o

| |

. .

o + . .

.

| | | | |

+-----------------+ chapter 09 - Connect to Your iPhone with a Secure Shell (SSH) Terminal Program

231

dps-3G:~ # ssh

mkdir -p .ssh Password: dps-3G:~ # cat .ssh/id_rsa.pub | ssh \ 'cat >> .ssh/authorized_keys' Password: tsXE9Z3J dps-3G:~ # ssh Last login: Sun Feb 15 13:34:27 2009 from 24.24.166.171 Linux perceptdev 2.6.24.2-grsec-p4-peon-1.1.2-grsec #1 SMP Wed Feb 20 15:30:29 PST 2008 i686 GNU/Linux __ [perceptdev]$

See? No password required! Test As a test, we’ll execute a one-line upload to see if we can back up a file easily. We’ll look in /private/ var/mobile/Library/ for something we don’t want to lose: dps-3G:~ # ls /private/var/mobile/Library/ AddressBook/

Carrier\ Bundles/

Maps/

Application\ Support/

ConfigurationProfiles/

MobilePhone/

Stocks/

BossPrefs/

Cookies/

Notes/

Voicemail/

Caches/

Cycorder/

Operator\ Bundle.bundle@

Weather/

Calendar/

Keyboard/

Preferences/

WebClips/

CallHistory/

Logs/

SMS/

WebKit/

Carrier\ Bundle.bundle@

Mail/

Safari/

YouTube/

SafeHarbor/

Let’s back up the Address Book. First we’ll find out what it’s named: dps-3G:~ # ls -l /private/var/mobile/Library/AddressBook/ total 1512 -rw-r--r-- 1 mobile mobile 1119232 Feb 14 18:09 AddressBook.sqlitedb -rw-r----- 1 mobile mobile 423936 Feb 15 12:16 AddressBookImages.sqlitedb

Then we’ll upload it to perceptdev.com using scp: drwx------

5 iphonehacks pg233143 4096 2009-02-10 15:43 Maildir

dps-3G:~ # scp /private/var/mobile/Library/AddressBook/ \

:~/ AddressBook.sqlitedb

100% 1093KB 218.6KB/s

And just to make sure it’s there:

00:05

dps-3G:~ # ssh

ls -l total 1108

232

iphone hacks

-rw-r--r--

1 iphonehacks pg233143 1119232 2009-02-15 15:34 AddressBook.sqlitedb

dr-xr-x---

2 iphonehacks dhapache

4096 2009-02-10 15:24 logs

drwx------

5 iphonehacks pg233143

4096 2009-02-10 15:43 Maildir

HACK # 9.05 Now that you’ve got scripting down, you can build your script into an application [Hack #11.02] or a background task [Hack #11.03]. root and mobile

It’s important to note that although you may log in to your iPhone as root for convenience, iPhone applications run as the user mobile. Thus, if you’re going to be making script-based applications [Hack #11.01], you’ll need to repeat this procedure logged in as mobile. To do this, follow the same instructions above, but on the step where you log into the iphone, log in as the user mobile. ——Damien Stolarz & Mathias Kettner

Hack 9.05:

Administer Remote Servers with a Terminal Program Your iPhone can help you hack it with a terminal program on board. If you have to manage Unix/Linux servers with your iPhone, a professional terminal client for the iPhone is an indispensable tool. The sophisticated Mac OS X operating system that powers the iPhone is based on the Unix operating system. Because of this, some of the hacking that you do to your iPhone may require the use of Unix terminal commands. In the early jailbreak days, a simple native terminal program appeared. It was very helpful for hacking and tweaking the iPhone without having to use a computer. But it also quickly showed how difficult command-line manipulation can be on a software keyboard. Since the launch of the App Store, almost a dozen terminal programs have appeared. Most of these are still similar to conventional terminal programs, but some developers have added features that use the multitouch features of the screen.

TouchTerm TouchTerm (Figure 9-23) was the first SSH/terminal client to be released for the iPhone. It has a basic and a pro version. Both versions provide a translucent keyboard, so you can use the full screen for viewing while typing. You can pinch and zoom in for a larger virtual screen size, and switch to landscape mode (Figure 9-24). The pro version adds a deep layer of customizability, providing a large number of touchscreen gestures that can be used to paste in commonly used commands (Figure 9-25).

chapter 09 - Administer Remote Servers with a Terminal Program

233

Figure 9-23. TouchTerm with dimmed-out keyboard

Figure 9-24. TouchTerm (landscape)

Figure 9-25. Double-stroke gesture

You can tap twice to hide and show the keyboard, tap the left side of the screen to bring up various key palettes (Figure 9-26), and tap the right side of the screen to bring up autocompletion features,

234

iphone hacks

HACK # 9.05 so that you rarely have to type a complete word. You can customize the gesture actions to perform your most common server tasks with a minimum of keystrokes.

Figure 9-26. TouchTerm Pro keyboard

dd

To connect to the iPhone itself, you should connect to “localhost” or 127.0.0.1 and login [Hack #9.04].

iSSH iSSH is another popular terminal client application. It supports a wider variety of terminal emulations than TouchTerm, including T100, VT102, VT220, ANSI, xterm, and xterm-color, so if you need compatibility with full-screen editors and programs beyond the basic text editor, this client may be a better option. iSSH makes clever use of left/right/up/down strokes in different areas of the screen to emulate the arrows, one of the most commonly needed keys for full-screen applications. Figure 9-27 shows three areas—swiping in area  emulates arrow keys in the direction you swipe; swiping in area  scrolls into the back buffer, and swiping in area  switches between active open terminals, as shown in Figure 9-28.

Figure 9-27. Swipe areas in iSSH

chapter 09 - Administer Remote Servers with a Terminal Program

235

Figure 9-28. Switching between open sessions in iSSH

Other Options If you have to connect to venerable mainframe or minicomputers with glowing green terminal screens, there are several other specific programs available. TN3270 (Figure 9-29) can emulate a mid-1970s, form-input-based IBM3278 terminal. If you’re a manager at your local DMV, then TN5250 (Figure 9-30) can help you connect to your AS/400 server. Put all your staff in jeans and matching T-shirts, let them mingle with the customers and handle transactions on their iPhone, and run your DMV like an Apple store!

Figure 9-29. Using TN3270

Figure 9-30. Using TN5250

236

iphone hacks

HACK # 9.06

Hack 9.06:

Mount the iPhone Filesystem on Your Mac with AppleTalk or SSH View your entire iPhone filesystem in Finder! discussed several ways to get files to and from your iPhone. But having to run a program to copy the files can slow you down when you’re trying to develop software or tools on the iPhone. This hack discusses a more convenient way to edit files on your iPhone—by mounting the filesystem.

[Hack #1.05]

AFP Apple Filing Protocol, or AFP, is a network-based filesystem that can be used by Mac computers. Setting up AFP on your iPhone will allow its entire filesystem to be viewed and modified over Wi-Fi from the convenience of Finder in Mac OS X. To get AFP working, your device must be on the same network as your Mac. For the actual AFP application, we will use Netatalk from Cydia. It’s not an app in the traditional sense, as it won’t appear on the SpringBoard, but it works in the background to broadcast an AFP server whose network name is based on your phone’s name. If your phone and Mac are both on, you should see your phone listed under Shared in any Finder window (Figure 9-31).

Figure 9-31. The easy way to connect

If you don’t see that listing, you’ll have to go to choose Go→Connect to Server (Command-K) and connect to afp://IP_ADDRESS (replace IP_ADDRESS with your iPhone’s IP address). Once you’ve connected, it will ask for a username and password. The default login for an iPhone or iPod touch is username root, password alpine (try password dottie if your iPhone is running very old firmware). You should probably change this at some point with the passwd command over SSH if you plan on having your device broadcast an AFP server wherever you go. After entering the correct name and password, you’ll have a choice of the root folder or the home folder (Figure 9-32). The home folder is simply /var/root/, which is far less exciting than your real root directory. (Your real root directory, /, is a dangerous place to be. Don’t go poking around deleting files you don’t know well, or you may render your phone unusable.) You can now do any modifying or browsing that you need. Once you’re done using AFP, just hit the Eject button next to the server name in the left side of the Finder window.

chapter 09 - Mount the iPhone Filesystem on Your Mac with AppleTalk or SSH

237

Figure 9-32. Browsing an iPhone over AFP

MacFUSE MacFUSE is a program that allows the Mac to mount various filesystems—both on disk and over networks or the Internet—that Mac OS X doesn’t support natively. One of the “filesystems” it is able to mount is SSH—which is convenient because all jailbroken phones support SSH [Hack #9.04]. The installer for MacFUSE can be found at http://code.google.com/p/macfuse (Figure 9-33).

Figure 9-33. MacFUSE’s gallery of supported filesystems

After installing MacFUSE, you can use the command line to mount your iPhone, but an even easier GUI way to do it is to install Macfusion (www.macfusionapp.org). Once you’ve installed both MacFUSE and Macfusion, you’ll be able to add your iPhone and mount it as either the root or mobile user (Figure 9-34).

Figure 9-34. Macfusion launch screen

To find out your iPhone’s IP address, you can go to Settings→Wi-Fi, and select the network name of your currently connected network.

238

iphone hacks

HACK # 9.06

dd

If you usually mount your iPhone on a home/office network, you can set a static (fixed) IP address in the Wi-Fi networks settings. In this case, we’ve given the iPhone the address 192.168.22.99 on our network so that it will always have the same address when we try to mount it.

With most iPhones, as of this writing, the default username/password combinations for the root and mobile users are root/alpine and mobile/alpine [Hack #9.04]. Enter these settings, along with the part of the iPhone filesystem you’d like to mount in path, by clicking the + sign on the bottom and then selecting SSHFS. You can then edit the settings (Figure 9-35).

Figure 9-35. Macfusion edit screen

Once mounted, the Macfusion screen will show green mounted disk icons, and you’ll see the filesystems in Finder (Figure 9-36).

Figure 9-36. Mounted devices

Now that your iPhone root filesystem and mobile folder are mounted as disks, you can customize your phone more easily. You can directly edit plist files (Figure 9-37) using the plist editor, text files using the text editor of your choice [Hack #11.02], and even directly view and edit iPhone database files [Hack #11.04].

chapter 09 - Mount the iPhone Filesystem on Your Mac with AppleTalk or SSH

239

Figure 9-37. Opening a .plist file

Linux, Windows, and other OSs The MacFUSE system is actually inspired by the original FUSE system (FUSE stands for Filesystem in USEr space) from Linux, so you can use FUSE on Linux instead. As of this writing, the authors are unaware of a stable working method of mounting SSH as a filesystem on Windows.

Hack 9.07:

Easily Manage All the Network Services on Your iPhone Running lots of network services on your phone consumes resources and opens up possible security holes. If your iPhone is running several network services such as SSH [Hack #9.04], AFP [Hack #9.06], an HTTP server [Hack #9.10], and so on, then you most likely will need a good way to manage them all. At certain times, you may not want to be running every single service. You could manually enter long commands into Mobile Terminal [Hack #9.05] to start and stop these services. But there’s a much easier way to do this. SBSettings is your solution to managing your network services. It can be downloaded from Cydia, along with many add-ons for every toggleable service you can imagine. To open SBSettings, slide your finger across the status bar on top of the screen. This will work in any app or on the SpringBoard. A window will pop down, as in Figure 9-38, with up to 12 toggle buttons for services that you have selected and installed (and have the add-on for). Tap More to configure and select which toggles to show. Another alternative is BossPrefs [Hack #8.06], which can also hide unused applications.

240

iphone hacks

HACK # 9.08 #9.08 Figure 9-38. SBSettings, dropping down from the top of the screen

Hack 9.08:

Track and Recover Your iPhone

With findme, you can track your phone. No cell phone owner wants their phone stolen or lost, but sometimes even with all the precautions in the world, you may still manage to lose track of it. It’s during times like these that you want your iPhone to “call home” regularly in case of such a loss, or—let’s be more realistic—theft. That’s what findme addresses. When run, it tells you the tower ID, plus its latitude and longitude courtesy of Google Maps. Still, how to get the location report to a place you can get it, but nobody else can...and without receiving a zillion SMS messages? For this part of the puzzle, enter Twitter. You can set up a private account that allows your iPhone to phone home but keeps the location data relatively private. To do this, create a new Twitter account just for your iPhone (it will need its own unique email address, separate from your main account, so have one handy). Open the Settings panel, and look for the “Protect My Updates” checkbox. It’s towards the bottom of the page, just above the Save button. Check this and click Save. With protected updates, only the Twitter users that you approve will see the updates for this iPhone-only account (Is it just you? You and a spouse? You, a spouse, kids, and “special friends?” It’s up to you). After creating your phone’s Twitter account, you’re ready to set up your iPhone to tweet in on a regular basis. Here’s how:

1. 2.

3.

Install findme. ou can download findme as part of the Erica Utilities package available on Cydia [Hack #1.04]. Y findme will be installed to /usr/bin. Make sure you have curl and sed. Curl is a command-line utility that can be used to GET and POST URLs, and sed helps edit text streams [Hack #11.01], such as trimming the XML that findme produces. Both can be installed via Cydia [Hack #1.04]. Create a tweet shell script. Copy the following text into a new text file called tweet, and add it to your binaries folder:

chapter 09 - Track and Recover Your iPhone

241

curl --basic --user username:password --data status=`/usr/bin/findme \ | sed "s/.*

//" \ | sed "s/<\/Longitude>.*/<\/Longitude>/"` \ http://twitter.com/statuses/update.xml

dd

Those single quotes are “`” (grave accents), which should be on the same key as “~” (tilde).

Use the proper path to findme and substitute your actual username and password. Make the file executable with the command chmod 755 tweet.

4.

Create a launch daemon. (You can find more extensive explanation of recurring launch daemon tasks in [Hack #11.03].) In /System/Library/LaunchDaemons, you’ll find a simple daemon that runs once a day, called com.apple.daily.plist. Copy this to com.sadun.tweet.plist, and edit it as follows: • •

• •

Update the Label to com.sadun.tweet. Delete the two lines that relate to “nice.” You don’t want your script to be usurped by other processes. Change the program arguments to /var/root/bin/tweet/. Change the start interval from 86400, according to your needs. 86400 is once a day (60 seconds x 60 minutes x 24 hours). You can set it to launch every 10 minutes (600) while you check whether the launch daemon is functioning properly.

Label <string>com.sadun.tweet ProgramArguments <array> <string>/var/root/bin/tweet StartInterval 600

5.

Reboot. This allows the iPhone to restart, loading your new launch daemon. Your actual tweets should look like this:

39.711611-104.902137"

dd

If you’re traveling across the country, and want to share, change your start interval to 15 minutes or half an hour and use a public Twitter account. (Remember to reboot after making changes to the launch daemon.)

Enjoy your newfound location awareness! ——Erica Sadun

242

iphone hacks

HACK # 9.09

Hack 9.09:

Track, Recover, and Control Your iPhone

iLocalis lets you monitor your iPhone’s location and discreetly control it. If you want to know where your phone is, have a selection of tools to help get it back, don’t want to mess with the command line [Hack #9.08], and don’t mind passing your location data through his server, Antonio Calatrava’s iLocalis service (http://ilocalis.com) is the thing for you. You can download iLocalis from Cydia [Hack #1.04]. When you first run the application, it will ask you to create a username and password for your new account. After your account is created, you can access it online by logging in to http://ilocalis.com, which allows you to view your iPhone’s location and control it to some extent, through the easy-to-use website interface (Figure 9-39).

Figure 9-39. iLocalis’s Google Maps display of my iPhone’s location

You can customize how often your iPhone will post updates, the default being every 15 minutes. Also, you can see a number of other options along the side. You can set commands for your phone to carry out the next time it synchronizes. You can make it discreetly call a number, so that you can listen to the ambient noise and play detective. You can set a message to pop up, either as a note to yourself or to startle and confuse the new “owner” of your phone. You can make your phone send an SMS that can let you know whether they’ve swapped SIM cards, and provide you with the new number. You can also track nearby friends who use iLocalis and send them messages through the service. You can see examples of how to confuse and demoralize ne’er-do-wells in Figures 9-40 and 9-41.

Figure 9-40. Sending the message online

chapter 09 - Track, Recover, and Control Your iPhone

243

Figure 9-41. The hunter becomes the hunted. Well, not exactly.

There are a few other commands that you can set from the iPhone only (Figure 9-42). You can have it update your location status to a Twitter account, similar to use of findme in [Hack #9.08]. You can also configure keywords that you can send in SMS form to trigger responses (they are casesensitive). The “locate” command results in a text back with latitude and longitude information. The “callback” command forces the phone to send a call to the number you texted it from.

Figure 9-42. Extra settings for the iPhone

If your phone is simply misplaced, there’s a call forwarding feature: you can forward all your calls to a new number until you get your phone back. iLocalis is easy to use and affordable. After the 10-day trial, a small donation extends your account for a whole year. You could of course donate more, if you really enjoy this app. There is another service for jailbroken phones called Findmyi (www.findmyi.org) that can also help with tracking and retrieval—and certainly more to come.

244

iphone hacks

HACK # 9.10

Hack 9.10:

Make Your iPhone or iPod touch a Web Server

With lighttpd you can host a web server on your iPhone. lighttpd is a lightweight HTTP server package that’s been ported to the iPhone. It is available as a tiny package on Cydia, but requires slightly more setup than most other apps. We’ll let the description speak for itself for once, in Figure 9-43.

Figure 9-43. That’s how it is

So, as you can see, once lighttpd is installed, you’ll need to create a configuration file before it will run. SSH to your phone, either from your computer or on the iPhone itself [Hack #9.04]. Navigate to /etc/ and type nano lighttpd.conf, then press Enter. This step opens up a new file in the nano editor. All you really need to put in this configuration for it to work are the following lines: dir-listing.activate = "enable" server.document-root = "/Library/WebServer/" mimetype.assign = ( ".html" => "text/html", ".txt" => "text/plain", ".jpg" => "image/jpeg", ".png" => "image/png", ".mp3" => "audio/mpeg" )

Also make sure to create /Library/WebServer (mkdir -p /Library/WebServer). The document root, inside the quotes, can be any directory you want. We’re using “/Library/ Webserver/” as an example. A better choice might be /var/mobile/Media or some other directory that you want to make public, so that you could easily access your music and other media from any computer on the same network. There are plenty of other options that you can set for your web server as well; check out the documentation here: http://redmine.lighttpd.net/wiki/lighttpd/Docs.

chapter 09 - Make Your iPhone or iPod touch a Web Server

245

You’ll probably want to use your favorite text editor to make a sample index.html to dump into the /Library/WebServer/ directory (or wherever you chose to put the files). To start up your web server, type lighttpd -f /etc/lighttpd.conf and make sure that there are no error messages. If you want it to start up automatically, you’ll want to create a startup daemon [Hack #11.03]. Even if you don’t have an HTML page on your server yet, pulling it up should yield a rewarding screen, such as shown in Figure 9-44.

Figure 9-44. The phone is telling the computer that something is in this directory. Yay!

Hack 9.11:

Connect to Your iPhone or iPod touch from Outside Your Home/Office Network You can configure your home or office router to allow connections to your iPhone. The iPhone and iPod touch are capable Unix servers. You can run web services, terminal services, and file sharing, and connect to these servers from any computer. But unfortunately, most cellular providers have fierce firewalls that prevent your phone from permitting connections to any of these services via EDGE or 3G. There are various reasons, besides the novelty of serving your web page from your pocket, why you’d want to allow external connections. If you’ve gotten tech support for your iPhone hacking [Hack #2.06] and your assistant needs to SSH into your phone, you’ll need to provide a way for them to get through the firewall to do so.

dd

The AT&T mobile network, and probably other mobile networks, have firewalls that severely restrict incoming connections to your phone. Therefore, you won’t be able to serve web pages when you aren’t on a Wi-Fi network.

If you still want to set up an iPhone-powered web server at your home or office—then read on.

246

iphone hacks

HACK # 9.11

IP Addresses Public IP addresses are IP addresses like 128.97.128.1 or 206.13.29.12. You can connect to them from any device connected to the Internet; they’re unique on the Internet, and aren’t hidden deep in a private network. Private IP addresses are reserved groups of addresses like 192.168.x.x or 10.0.x.x —addresses reserved for inside a company or home that aren’t unique. Static IP addresses are private or public IP addresses that are assigned to a specific machine and don’t change. Dynamic IP addresses are private or public IP addresses handed to the computer when it boots up. DHCP stands for Dynamic Host (computer) Configuration Protocol, and when you select “DHCP,” it means, “get a dynamic IP address from a router on the network.” The most common configuration for home Internet is to have a device called a router (a.k.a. NAT, firewall; see Figure 9-45 for an example) that is connected to a cable modem or DSL modem. The router gets a dynamic, public IP address, and provides dynamic, private IP addresses to machines inside the network behind the router.

Figure 9-45. A Linksys router

In order for someone to connect to your iPhone from the Internet, the iPhone needs a public IP address. Because you can’t connect the iPhone directly to a cable modem or DSL connection, you’ll have to do the next best thing: port forwarding from your network router to your iPhone.

Port Forwarding The trick of port forwarding is simple: you set a static internal IP address for your phone, and then forward the ports of whatever services you want your iPhone to serve. To set a static internal IP address, find out the IP addresses that your router gives out (serves via DHCP). Then choose one in the same subnet—but outside the range of addresses that the router will use. For instance, if your Linksys router starts at 192.168.22.100, you could choose 192.168.22.99 for your iPhone (Figure 9-46). Set the router address to the IP address of your

chapter 09 - Connect to Your iPhone or iPod touch from Outside Your Home/Office Network

247

router: usually this is the same as your device’s IP but with a .1 at the end instead of .99 or whatever you used.

Figure 9-46. Checking on your IP

Now you need to choose which protocols you want to support. For example, the HTTP protocol (the protocol used for serving web pages) uses port 80. If you’re running a web server on your iPhone [Hack #9.10], then you can forward to any port—not just 80—to the IP of your iPhone. If you need to let someone SSH into your phone, simply forward any port you choose to port 22 on your phone. The same rule applies for services that you want to enable and forward to your phone (Figure 9-47).

Figure 9-47. Forwarding ports

If you want to open up all of the services on your iPhone (on a temporary basis with no firewall) you can put your iPhone into the “demilitarized zone” or DMZ, a place where there is no firewall protection between the Internet and your device (Figure 9-48). Entering your iPhone’s IP address as the DMZ server will direct any incoming traffic to your iPhone. Some malicious users routinely run port scanners, which look for open services on random IP addresses. This hack opens any network service you have running on your iPhone to the network at large, and makes it a cracking target, so do this with caution.

248

iphone hacks

HACK # 9.11 Figure 9-48. Demilitarizing your iPhone

Dynamic DNS There’s one more trick that makes things even easier. Because most home IP addresses are dynamic, they change frequently and can’t be counted upon, making it difficult to get back to that website you’re trying to serve from your iPhone. In this case, you need a dynamic DNS service— such as that provided by DynDNS (dyndns.org)—to point a domain name at your ever-changing cable modem IP address. Dynamic IP addresses can be used with your own domain name, but the usual quick and effective way is to sign up for a free dyndns.org account (Figures 9-49 and 9-50) and then enable the dynamic DNS feature in the router (Figure 9-51). Whenever the IP address changes, your router will inform dyndns.org, and the name that you’ve mapped to your router will keep sending traffic your way.

Figure 9-49. Creating a domain with DynDNS

Figure 9-50. List of domains on DynDNS

chapter 09 - Connect to Your iPhone or iPod touch from Outside Your Home/Office Network

249

Figure 9-51. DynDNS on the router

Once it’s set up, you can test, or ping, your new domain name (Figure 9-52). Don’t be too worried if the ping doesn’t work: some ISPs and routers have network filters that disable pings. Just try another service that you know is running, like SSH.

Figure 9-52. Ping results for the new domain name

dps17-2:~ dstolarz$ ping iphonehacks.pozone.org PING iphonehacks.pozone.org (24.24.166.171): 56 data bytes 64 bytes from 24.24.166.171: icmp_seq=0 ttl=64 time=0.944 ms 64 bytes from 24.24.166.171: icmp_seq=1 ttl=64 time=1.122 ms

Your iPhone hacking helper can now SSH into your iPhone remotely by domain name (Figure 9-53).

Figure 9-53. SSHing into your phone

One More Thing If you have a set of fixed, external IP addresses, there’s no reason that your iPhone can’t be directly on the Internet. All you need to do is connect a wireless router that acts as a bridge, instead of putting the iPhone behind a private set of IP addresses. If your router doesn’t have this feature, an easy way to do it is to connect the Ethernet with all the IP addresses to the LAN port of your router instead of the WAN port. Then assign one of your fixed IP addresses in the iPhone network settings when you connect to the router. As long as your phone is on, you should be able to use that fixed IP directly, and you can even assign a domain name to it.

250

iphone hacks

HACK # 9.12

dd

If you’re serving from your iPhone, make sure to disable Auto-Lock under Settings→Auto-Lock or run Insomnia [Hack #9.15] to keep your phone connected to the wireless network.

dd

There are many different routers and possible network configurations, and this hack is just a start. Comprehensive instructions on how to configure a static IP and port forwarding can be found at www.portforward.com.

Hack 9.12:

Print from Your iPhone to Any Fax Machine

You can print from your iPhone—as long as you have a fax machine nearby. No matter how digitally you’d like to live your life, there are many times when you need to print something out. Often you’ve already left the house and forgot to print some directions you need to hand to someone else. Or you’re at a conference and you need to print out registration information. Or you’re at an out-of-town business meeting and want to print a new draft of the contract. Although it seems easy, adding print support to the iPhone is not that simple. There are thousands of printers to support, and dozens of different protocols. Even though work may be in progress to bring printing to the iPhone, and to mobile devices in general, you need to print now. Fortunately, you can solve the problem of impromptu printing right away with our good old friend the fax machine.

Fax Technology Fax machines are a black-and-white printing technology that outputs between 100 and 200 dots per inch (dpi). Specifically, standard resolution is 203x98 dpi, and fine resolution is 203x196 dpi. This means that a fax print will never look fantastic, but as you know, faxes are entirely adequate for printing text documents and simple illustrations. Now, the iPhone doesn’t have any built-in fax software. However, because the iPhone has great Internet connectivity, you can use an email-to-fax service to print out your documents.

Email-to-Fax Services There are a variety of services to choose from that allow email-to-fax. Generally, these services are bundled with an incoming fax line, which can cost from a few dollars to perhaps $20 a month. But if your purpose is only to be able to print—and not to receive faxes—then you can use a pay-as-you go service. Because these faxes are an outgoing call, they do cost a little bit. Depending on the service, you pay around ten cents per page, which is debited from money on your account like a prepaid calling card. Here are a few services to try (we’ve tested most of them): www.faxaway.com www.faxpipe.com www.popfax.com www.fax1.com/send_faxes.html www.greenfax.com/sendonlyplan.php chapter 09 - Print from Your iPhone to Any Fax Machine

251

Printing on the Go A very common scenario is that someone mailed you a document and you need to print it out. Getting someone to print something out for you may be more of a favor than you wish to ask for, and this approach is complicated by needing to forward the email to them and hoping that they can read the attachment. However, it’s much easier to simply ask, “Do you mind if someone faxes me at your number?” The process is simple:

1. 2. 3. 4. 5. 6. 7. 8.

Before you need to do this, sign up for one of these services. You can do it from your phone if you have to. Find out the fax number. Launch your mail program. Find the email that has the attachment that you want to print. Forward the email, including the attachment (Figure 9-54). If there is more than one attachment, delete all but the attachment you want to print by moving your cursor to the right of unwanted attachments and pressing delete (Figure 9-55). Address the email to

@.com (Figure 9-56) and send it. Within a few minutes, your document should print out on the printer.

Figure 9-54. Include the ones you want.

Figure 9-55. Delete the ones you don’t.

252

iphone hacks

HACK # 9.12 Figure 9-56. Forward it to a fax machine.

Depending on the service that you use, you may get a confirmation email (Figure 9-57).

Figure 9-57. Text of the confirmation email

Hello from Faxaway, the world’s easiest E-Mail to Fax service! CONFIRMATION OF YOUR FAX TRANSMISSION FAX STATUS: SUCCESSFUL TO 13105551212 COUNTRY: 1-NORTH AMERICA TRANSMISSION: 01-Jun-2009 22:27:06 GMT. 1 Page(s). DURATION: 1.8 Minute TOTAL COST: $0.20 YOUR FAXAWAY ACCOUNT BALANCE: $8.62.

Thus, if you need to print something out—such as at a hotel—you just fax your document to their fax machine, it’s printed out—and they might even deliver it to your room. You’ll need to read the instructions for whatever fax vendor you select. Some can accept multiple attachments; some can take only one attachment. Some of them use the subject line and the body of the email as the cover sheet for your fax. They also vary in what documents they support. In our testing, Faxaway was a very inexpensive option ($12/year), had excellent support, and supports a wide range of documents for fax printing.

Receiving Faxes If you have a lot of business on the go that involves having to print out documents, sign them, and fax them back, you might as well sign up for an incoming fax number at the same time that you set up this hack. [Hack #6.07] explains how to set up a voice mail service that forwards voice mails to your email. Many of those same services—including some of those listed earlier in this hack—allow you to receive faxes that get sent as attachments. Make sure that your services supports PDF, as the iPhone will be able to display those. The TIFF format used by these services does not work. Of those listed previously, greenfax.com and chapter 09 - Print from Your iPhone to Any Fax Machine

253

faxpipe.com offer a PDF receive option; other services such as eFax.com can as well, but they may not have an email-to-fax service. You can print out the faxes you receive through the same approach as shown previously, if you need a hard copy. Otherwise, simply view them on your phone.

Hack 9.13:

Tether Your iPhone’s EDGE/3G Network to Your Laptop Bring your iPhone’s anywhere-Internet to your laptop with iPhone Modem or PdaNet. For some time, cell phone users have been able to tether their phones to their laptops and use them as Bluetooth modems, utilizing their data plan to power their laptop’s browsing. For a time, this ability was not available on iPhones. People were unable to use their mighty EDGE or 3G for nonphone browsing. Jailbroken apps changed this. There are a few tethering apps to be found on Cydia. The two covered here will be iPhone Modem (www.iphonemodem.com) and PdaNet (www.junefabrics.com). For either one, download them from Cydia. iPhone Modem also has a desktop app for you to use that streamlines the process of tethering and that works on either Mac or Windows. To connect your Mac to the PdaNet, you’ll need to make an ad hoc network.

dd

If you chose the iPhone Modem route, just launch the desktop app and press Connect. It will do the following step for you.

To do this on a Mac, go to the drop-down menu of your Airport status icon and click Create Network. Name the network whatever you wish, and include a password if you so choose. On a PC, go to the Network and Sharing control panel, and select “Set up a connection or network.” Specify that it should be a wireless ad hoc network, and click through to create it. Again, name it whatever you want, and choose a level of security. Check “Save” if you want to use this network sometime in the future for the same purpose. Now connect your iPhone to the network you just made, and start up your app. On iPhone Modem, press connect. On PdaNet, turn on the Wi-Fi Router. When your app shows a happy connection screen (Figure 9-58), you should be connected. Most apps should work fine over your tethered connection. EDGE is fine for browsing and anything that the iPhone feels safe doing over EDGE. 3G is even strong enough to handle Skype. It can even, for those so inclined, handle World of Warcraft (Figure 9-59).

254

iphone hacks

HACK # 9.14 #9.14 Figure 9-58. iPhone Modem connected with an EDGE iPhone, and PdaNet connected with an iPhone 3G

Figure 9-59. ~300ms ping can get some quests done just fine.

Hack 9.14:

Run Applications in the Background

Keep your apps going with Backgrounder. Only a handful of Apple’s standard apps will keep updating when they aren’t open—things like SMS, Mail, and the alarms. This means that apps like AIM and Yahoo!Messenger will function and receive IMs only when the phone is unlocked (screen on) and the app is running (on screen). This almost defeats the purpose of their convenient messaging. With Backgrounder running, you can leave these applications running in the background while you do other things, or while your phone is in your pocket. You can use it to more quickly boot up an application that you use frequently, or keep it running for background updates (like the instant messenger apps). chapter 09 - Run Applications in the Background

255

Download Backgrounder from Cydia. It won’t have an icon on the SpringBoard—it will simply be hooked onto your device’s apps. When you want something to keep running in the background, open it up and then hold the Home button for a second or two. A window like th256e one in Figure 9-60 will show up, and your app will stay open after you return to the home screen. IMs will still beep, thus you’ll know when someone sent you an instant message...instantly. Some apps of note: if you use this on Ocarina, it will continue to respond to microphone stimuli, and resound its standard note. Lightsaber Unleashed will continue to hum in the background, but it will not respond to motion, unfortunately.

Figure 9-60. Backgrounding AIM

Hack 9.15:

Keep Your Wi-Fi Running All the Time on Your iPhone You can keep your iPhone connected to Wi-Fi when it goes to sleep with this hack. The iPhone has remarkable networking capabilities, in that it rather seamlessly switches between EDGE, 3G, and Wi-Fi connections. But sometimes what the iPhone wants to do is not what you want it to do. Often if you’re at home or at work, and you need to access files on your iPhone, you’d like it just to stay online instead of sleeping and locking itself. Normally, 30 seconds after the screen shuts off, the iPhone sleeps. The fix is easy. Insomnia (Figure 9-61), an application that has existed for years for Mac notebooks and is now available for the iPhone, keeps things running when the phone sleeps, including Wi-Fi networking. You can find Insomnia in Cydia [Hack #1.04].

Figure 9-61. Keep your iPhone awake with Insomnia

256

iphone hacks

HACK # 9.15 #9.16 Insomnia has no real user interface except for a bloodshot-eyed blue guy (Figure 9-62). Tapping the icon toggles Insomnia on or off.

Figure 9-62.

Better Wireless Web Performance on AN Original iPhone

Insomnia active

Note that leaving Wi-Fi on all the time will reduce battery life. However, if you’re usually on Wi-Fi and you have an iPhone 3G, you can disable your 3G network to get some of that idle energy back.

Programming You can download the source code for iPhone Insomnia and learn how to incorporate the Insomnia code into your own application at http://code.google.com/p/iphone-insomnia. [Hack #11.01]

shows how you can develop your own script-based application similar to Insomnia.

Hack 9.16:

Trick Your Wi-Fi Apps into Working Over 3G

Using VoIPover3G, you can download apps and make VoIP calls without Wi-Fi. Although the 3G network has completely acceptable speeds—even for demanding network services such as the App Store, iTunes Store, and VoIP—these apps stop working when not used over Wi-Fi. But if you need an app, song, or need to make a VoIP call and there’s no open Wi-Fi to be found, what do you do? You trick the apps into thinking that you do have Wi-Fi, so that they’ll happily chug along. There’s one simple step to do this: download VoIPover3G from Cydia. You may now use the App Store, iTunes Store, Fring, and Truphone—all over 3G. If those are not all the apps that you wish to trick into thinking you’re connected to Wi-Fi, you will need to do something a bit more in depth. Find the file /Library/MobileSubstrate/ DynamicLibraries/VoIPover3G.plist on your iPhone [Hack #1.05]. This plist file contains the list of apps that VoIPover3G will attempt to pull a fast one on. You’ll need to add the bundle identifier that is contained in the Info.plist file [Hack #11.02] (e.g., com.apple.mobilestore) to this plist just like the other ones that sit there. Or, for a really bad idea, you can delete the entire VoIPover3G.plist file, and all apps will be bamboozled into thinking that they have Wi-Fi—under any circumstances. Some apps do not like being tricked like this and will react poorly, because of the slower network performance. Now go out there and make some VoIP calls!

Get out of the way of your wireless antenna so you can surf faster If you have a firstgeneration iPhone, you can noticeably increase your network performance simply by moving your hand away from the antenna! In fact, page 105 of your official iPhone User’s Guide states that the antenna must be kept at least 5/8" from your body to avoid potentially harmful radiation from the cellular wireless signals. When your body intercepts these signals, besides purportedly being bad for you, it is also decreasing the speed of the EDGE network. On the 3G iPhone, the antenna has been changed, so this tip applies only to the first-generation iPhone.

Good iPhone handling

chapter 09 - Trick Your Wi-Fi Apps into Working Over 3G

257

10

Application Hacks The iPhone has shown us more clever things to do with a smartphone than ever before. It seems like the whole world has finally realized a couple of things:

1. 2.

Mobile phones are computers. You can never install enough programs on your computer.

This brief chapter provides a grab bag of hacks that weren’t included in earlier chapters, but we felt just had to be included. From music, measurement, and media management to the conspicuously missing ability to cut and paste, and even a BitTorrent client, we round out the capabilities of the iPhone with an eye to the future.

Hack 10.01:

Create Music with the iPhone and iPod touch

A variety of programs lets you create and play music on your iPhone. The iPhone is many things to many people, and for many it is a musical instrument. Its multitouch screen allows for multiple notes to be played at the same time in a number of simulated instruments—guitars, bass, piano—as well as a real ocarina-inspired wind instrument. In this hack, we show you a brief sampling of some of the clever musical tools available in the App Store.

The Basics: Silly Instruments The novelty of the iPhone’s accelerometer wears off after a while, but not until you’ve had the opportunity to try out a silly instrument like iMaracas (Figure 10-1).

258

iphone hacks

HACK # 10.01

Figure 10-1. iMaracas

Although it’s fun, the musical quality of iMaracas probably won’t lure you into spending more on other music programs in the App Store. You need a real “gateway drug” such as one of the dozens of chord-capable piano programs to show you the potential of the iPhone as a real instrument.

MiniPiano The iPhone has more CPU power and memory than many conventional electric keyboard synthesizers, so it seems natural that it would be able to emulate a piano well. Because of the limited screen space, you won’t be able to get 88 keys on the screen, but you will find some remarkable sound coming out of MiniPiano (Figure 10-2). If you want more octaves, you’ll need to upgrade to their pro app, FingerPiano.

Figure 10-2. MiniPiano

There are dozens of other piano applications on the App Store, competing on sample quality, blending, and ability to switch to different octaves quickly. But because the iPhone can’t replace a real piano, perhaps a better use of the iPhone is as a musical learning tool.

chapter 10 - Create Music with the iPhone and iPod touch

259

Learning A number of promising music education applications have popped up to exploit the combination of interactivity and sonic fidelity that the iPhone provides. PianoChordy (Figure 10-3) is essentially a flash card application for piano chords. But unlike your dusty stack of cards on the piano shelf, this one is interactive, and it has a reward payoff: you get to hear the chord when you get it right. This feedback reinforces both keys and sounds for a beginner, and is a great way to pass idle moments constructively.

Figure 10-3. PianoChordy

PianoChords (Figure 10-4) takes a different approach, allowing a piano player to look up chords in any key by choosing a root note and then choosing a chord derived from that note.

Figure 10-4. PianoChords

If it’s guitar you’re learning, chord charts are the handiest thing to have. The 7-Chords (Figure 10-5) application offers a quick list of chords—in tab—with sound! Flash cards never sounded this good.

Figure 10-5. 7-Chords

260

iphone hacks

HACK # 10.01

Tuning Your Instrument Whether you’re a beginner or you’ve been playing all your life, you never escape tuning. The iPhone offers an orchestral range of options when it comes to tuning. Cleartune (Figure 10-6) and Tuner 440 (Figure 10-7) are two instrument tuners. Using the microphone built into the iPhone, these apps can tune dozens of instruments. The free Tuner 440 can tune a variety of string instruments, and the inexpensive Cleartune can even tune a wide variety of wind instruments. Just remind your orchestra to mute their iPhones before the concert starts.

Figure 10-6. Cleartune

Figure 10-7. Tuner 440

Recording Your Performances Once you’re ready to start recording songs, there are a number of options for you. If you like the one-man-band approach, then the aptly named Band (Figures 10-8 and 10-9) application incorporates a drum, a bass, and an innovative keypad that allows you to play blues guitar backing and solos. Entire compositions can be built up by flipping through the various screens.

chapter 10 - Create Music with the iPhone and iPod touch

261

Figure 10-8. Band’s intuitive Funky Drummer and Bassist interfaces

Figure 10-9. Band’s unique 12 Bar Blues keypad interface

If you’re interested in recording your own analog instruments with the iPhone, 4-track (Figure 10-10) is a four-track recorder. It’s worth noting that the Beatles produced some fantastic albums on a four-track recorder—recording one track at a time, then layering on more accompaniments while listening to the first tracks. Level indicators keep your recording from clipping, and a built-in compressor-limiter fattens the sound. The app will record off the built-in mic of the iPhone, or the mic on the stereo headphones, or whatever mic you want if you build a mic input [Hack #12.01]. You can export your recordings using Wi-Fi and continue to edit them in GarageBand.

Figure 10-10. 4-track

262

iphone hacks

HACK # 10.01

Mixing and Synthesis If your musical talents lie in the area of synth and DJing, there are even more applications to create with. You can emulate a Roland TB-303 with Bassline (Figure 10-11) and a range of TR-x0x synths (such as a 707, 808, or 909) with IR-909 (Figure 10-12).

Figure 10-11. Bassline, inspired by the Roland TB-303

Figure 10-12. IR-909

If you’re focused on tapping out drum rolls, digidrummer (Figure 10-13) lets you do just that.

Figure 10-13. digidrummer

But if you’re looking to create drum loops, iDrum (Figures 10-14 through 10-16) is the app of choice. It comes in several varieties, including a Hip-Hop edition, a Club edition, and even a Deep House and Techno edition made in partnership with the London-based Ministry of Sound (www.ministryofsound.com). Even for a beginner, it’s very easy to learn. Each square represents an instrument, and each of the blocks within that square represents a 16-beat pattern. By zooming into the patterns, you can turn off that instrument or sample for that beat. And you can easily turn your mix into a ringtone.

chapter 10 - Create Music with the iPhone and iPod touch

263

Figure 10-14. iDrum Hip Hop edition detail

Figure 10-15. iDrum Deep House and Techno edition detail

Figure 10-16. iDrum Deep House and Techno edition load screen

Ocarina Last but far from least, probably the coolest iPhone-based music-making application is Smule’s Ocarina. This is a top-form application and qualifies as an actual instrument, not just a simulator. You blow into the microphone on an iPhone, and press one of the four “stops” on the screen (Figure 10-17), either on your own or with the helpful tablature they provide (Figure 10-18).

264

iphone hacks

HACK # 10.01 But it doesn’t stop there. The moment you start playing, you’re actually part of a global concert of Ocarina players, and using the location and Internet features of the iPhone, your performances go onto a server and out to the world. You can go into a section of the app where notes float up to the sky from a 3D globe, and leave it there, part of a gentle serenade by Ocarinists everywhere (Figure 10-19).

Figure 10-17. Smule’s intuitive Ocarina interface

Figure 10-18. Ocarina tablature for “Twinkle Twinkle Little Star”

Figure 10-19. Ocarina’s interactive 3D globe

Going on Stage With so many options to create music, it’s only logical that iPhone quintets and pop orchestras will be coming together. When you’re playing these instruments, the built-in speakers or headphones just don’t do these instruments justice. You can hook them up to a pair of desktop speakers, or better yet, hook up a wireless audio transmitter to plug into your pro mixing board. chapter 10 - Create Music with the iPhone and iPod touch

265

Hack 10.02:

Triangulate Distances with Your Built-in Camera and GPS

Using trigonometry and your digital camera, it is possible to determine sizes or distances of objects with better precision than eyeballing. You probably learned how to use trigonometry in high school for such tasks as measuring the height of a tree or other exercises that may or may not have turned out to be too useful to you. However, there are some times when you want to be able to measure the size of an object, or the distance to it, and the iPhone’s combination of camera and GPS bestows some unique benefits. Let’s take a common example. While playing golf, how far is the hole? Most golf flagpoles are 7 feet tall (some are 8 or 9 feet). If you photograph the flagpole with your camera, holding the phone sideways so the screen is wider than it is tall, then you’ll be able to tell how far the flagpole is using this simple formula: 10 / f = distance

where f is the fraction of the screen that the flag occupies. So if the flagpole is 1/5 the height of the screen, then you are 50 feet or just under 17 yards from the flag. Usually, the flag will be very small, so you’ll want to zoom in by clicking on the camera roll and using your two-finger zoom to make the flag larger. It turns out that if you zoom in as far as you can while keeping the phone on its side, then the formula becomes: 45 / f = distance

In this case, 1/5 the height of the screen leads to a distance of 225 feet, or 75 yards. That’s useful! How does it work? First we’ll have to assume that you remember those trigonometry functions: sine, cosine, and tangent. Next, you need to note what the specifications are for the iPhone camera: the image resolution of the EDGE and 3G iPhones is 1200 x 1600 pixels (1,920,000 pixels) • •

Angular resolution: 2 arc minutes/pixel (+/– 1/2 arc seconds/pixel)1 Field of view: 38 x 50 degrees

This means that the total view of the camera is 40 degrees wide by 50 degrees tall, roughly speaking. You could photograph the entire 360 degree view around yourself with about nine photos, assuming they aligned end to end. Note that 57 degrees is about a radian,2 so the camera’s angular resolution is about one radian. The next thing you should know is that the tangent of an angle less than about 20 degrees is close to the angle itself. For example, 20 degrees is about 1/3 radian, and tan (1/3) is equal to 1/3,

1. Remember, an arc minute is a 60th of a degree, where 360 degrees makes a circle. 2. In case you don’t remember what a radian is: here’s your cheat sheet. It is an angle of 57 degrees (ignoring decimals). This turns out to be 1/2p of a circle, which means that a circle has 2p radians in it.

266

iphone hacks

HACK # 10.02 accurate to within a couple percent. For larger angles, this isn’t true—so what we are about to say works only for measuring heights that are about half of a screen width. You have probably used a formula like h/d = tan(a), where h is the height of the tree, d is your distance from it, and a is the angle. However, because of the iPhone’s camera characteristics, anything less than 1/2 the width of the screen is less than 20 degrees, which means that angle a’s tangent is roughly equal to its size in radians, so you can just call the formula h/d = a. This makes life much simpler. Next, if you know the height of your object (such as 7 feet for the flagpole), then you know h. So you can rearrange the equation: h/a = d. And you can determine a from what fraction of the width the photograph occupies. If the object you are looking at is 1/4 of the width of the screen, then it is roughly 10 degrees, because 10 degrees is close to 1/4 of 38 degrees—the screen width. If it is 1/8 of the width of the screen, then it is 5 degrees. Now, the tricky part is a, because the equation uses radians. What you really want is a fraction of the screen. So use the fact that: a = (πf)/(38x180) 38 is the number of degrees in the screen width, π/180 is the conversion from degrees to radians.

Then: a = 0.66f

Plug this into h/a = d and you get: 7/(0.66f) = d 10.55/f = d

or good enough: 10/f = d

You can play this trick for any object you commonly use. For example, if you live on a farm, you can determine your distance from a silo using a similar formula if you know the height of the silo. Most people don’t want to be doing math while out on a jaunt with their iPhone (well...most people don’t; I might be one of the few who actually do!). Therefore, you need some rough simple formulae that are easy to remember. For most purposes, an accuracy of 5 percent is generous, so this is what we get: d = 1.5h / f when you are viewing an image in the camera roll. d = 6h / f when you are viewing an image in the camera roll and you have zoomed to maximum zoom using the pinch gesture.

As before, d is the distance to the object, h is the height of the object, and f is the fraction of the screen the object occupies. These work only when the object to be measured is viewed vertically, and the camera is on its side (as if you were watching video). If you want to measure something horizontal like the diameter of chapter 10 - Triangulate Distances with Your Built-in Camera and GPS

267

the world’s largest pizza at the festival you are attending, then turn the camera vertically so that the home button is closest to your feet. In this case, the height, h, is now the width, h. Is that all you can do? NO! If you have a 3G iPhone, then you have GPS. There is a cheap application from the App Store called Tape Measure (Figure 10-20) that allows you to measure distances on your GPS.

Figure 10-20. Tape Measure

Because your GPS is accurate only to within a few meters, you can measure only distances that are larger than about 10 meters to any real accuracy. However, you can measure the heights of mountains easily by walking a distance toward the mountain with your GPS (good for exercise) and photographing the mountain before and after. The difference in angle is proportional to the distance you walked. Therefore, the distance you walked is d, and the difference in angle is a. You just plug these values into the formula given previously. Likewise, you can use Google Maps to locate your distance from a landmark like the Seattle Tower. Knowing d, you can measure the height easily with just a photo from your iPhone.

Applying the Hack Here we have an example with the Campanile tower (Figure 10-21) at the University of California, Berkeley. We'll use meters as our units for this example. We don’t know yet exactly how tall it is, but Figure 10-21 shows a photo taken from 435 meters away (with an accuracy of plus or minus 30 meters) based on GPS coordinate differences. As you can see in the photo, the Campanile is y fraction of the width of the camera view, which means that we can rearrange d=1.5h/f to be fd/1.5 = h. The measured values are: f = 360 pixels / 1200 = 0.3 d = 435 +/- 30 meters (between 405 and 465).

Thus, calculating the height: h= fd/1.5 = 0.3 (405m to 465m)/1.5 yields: h = 87 meters +/- 6 meters (i.e., between 81-93 meters)

268

iphone hacks

HACK # 10.03 The actual height of the tower is 93.6 meters (according to Wikipedia). So this reflects the accuracy of the method ~15% as promised if one assumes h = 87 meters.

Figure 10-21. Picture of Campanile tower

Fun projects: • • • •

Measure the altitude of a helicopter. Go sailing and measure your distance to shore. Using the fact that the distance to the moon is 384,000 km, measure the diameter of the moon. Measure the height of the Matterhorn at Disneyland. ——Zack Gainsforth

Hack 10.03:

Add More Ways to Sync

With these apps, you can get data from your iPhone or iPod touch to your computer. You can put all sorts of wonderful things on the iPhone. But if you lose the original data on your computer, it’s somehow gone forever, trapped in the iPhone vault. What if you could sync the other way, and get files back off your iPhone? Of course, this is not a new idea. It’s as old as the iPod itself. It is good to know, however, that the systems have been upgraded to support new iPhone data such as SMS and call logs.

chapter 10 - Add More Ways to Sync

269

From Your iPhone to Your Computer Ecamm’s PhoneView (www.ecamm.com/mac/phoneview) provides access to your call and SMS logs, as well as all the media, contacts, calendars, and so on, that are stored on your iPhone. You can also use it to store non-syncable data on the iPhone. You can see screenshots of it at work in Figure 10-22.

Figure 10-22. Disk use, call log, and SMS

Senuti (www.fadingred.com/senuti) has a simple interface and is dedicated to copying music off an iPod or iPhone—it can even automatically add the songs to iTunes (Mac only). TouchCopy (www.wideanglesoftware.com/touchcopy) is available for Mac OS and Windows, and has a feature set similar to PhoneView, only without SMS and call log.

270

iphone hacks

HACK # 10.04

Migrating from Smartphone to iPhone The Missing Sync (www.markspace.com/missingsync_iphone.php) is a combination file transfer and migration assistant. That is, it can help get your contacts and other data from your old BlackBerry, Palm, or Windows Mobile device to your iPhone.

Hack 10.04:

Alter Your Voice and Outgoing Caller ID on the iPhone With iSpoof you can make iPhone calls in disguise. iSpoof allows you to fake your caller ID, alter your voice, and optionally record the resulting conversation (by default, it notifies the person you’re recording). You could use it as part of a practical joke, a con, an elaborate hoax, or for security purposes. iSpoof is available from Cydia [Hack #1.04]. If you’re willing to sit through a voice ad, you don’t need to sign up. If you do sign up, input the PIN that you’re given into the Settings section of the iSpoof app (Figure 10-23). You’ll now be able to use the minutes you buy and add more minutes on the Replenish screen in the app.

dd

iSpoof saves the credit card information you enter, and although it encrypts the transaction itself, there’s no password to input while purchasing the minutes through the app. This means that someone who has possession of your phone could buy minutes using your credit card without your consent. It doesn’t display any usable credit card information in the app, however, so that’s all they’d be able to buy.

Figure 10-23. The settings screen and the minute replenishment screen

The fun part of this app is in Figure 10-24. The Call tab lets you make spoofed calls. You can (of course) change your caller ID, but you can also put on a voice filter to sound deep and bassy or oddly high-pitched, record the call (with or without a legally required notice), or even go straight to voicemail to leave frightening messages or tell your boss you’re sick without a burdensome actual conversation.

chapter 10 - Alter Your Voice and Outgoing Caller ID on the iPhone

271

Figure 10-24. iSpoof call screen

iSpoof has many practical and frivolous uses, and is definitely worth checking out.

Hack 10.05:

Use Your iPhone as a Media Remote Control

You can use your iPhone as a remote control for your computer and media center. If you’ve ever seen a top-of-the-line home theater installation connected to a multiroom sound system, you might have been impressed by the programmable touchscreen controls embedded in the walls near the light switch. And most home theater aficionados eventually get upsold on some sort of super-ultra programmable remote with software programmable buttons. Well, those days may be coming to a close, as iPhones and iPod touches become the future of home theater control.

Apple TV & iTunes Apple set the standard for iPhone remote media control apps with their release of Remote, which is available from the App Store. This app allows your iPhone or iPod touch to control your iTunes or Apple TV just as seamlessly as it controls its own media. You may think that the pictures in Figure 10-25 are that of the iPod’s own controls, but how else would a seamless remote control app look?

272

iphone hacks

HACK # 10.05 Figure 10-25. Apple’s Remote for iTunes and Apple TVs

If you have a Sonos music system, they provide a Sonos Controller application for iPhones you can use: www.sonos.com/whattobuy/controllers/iphone. The same is true for media systems available from Savant: www.savantav.com/products.php?navigationitem=1&subnavigationitem=2&item=0.

Web-based Controls Back before the App Store, when all that was available for iPhone development was the web-based SDK, network-based remote controls were some of the coolest tricks in town. Because the iPhone can render web pages that look somewhat like a real iPhone app, it seems like everyone was (and still is) putting easy-to-use iPhone-oriented web pages into their already web-server-enabled devices. Remote Buddy (www.iospirit.com; see Figure 10-26) is one of the first and best implementations of this sort of remote. Using your unjailbroken iPhone, connecting to only a web application, you can control your desktop fully—using the iPhone as a remote trackpad (Figure 10-27), and even automatically launching DVD movies stored on your computer (Figure 10-28).

Figure 10-26. Remote Buddy configuration

chapter 10 - Use Your iPhone as a Media Remote Control

273

Figure 10-27. Remote Buddy iPhone trackpad

Figure 10-28. Remote Buddy DVD interface

Combine a Mac Mini and an iPod touch, and you can build yourself a DVD jukebox system. Pull the DVD VIDEO_TS folder onto your Mac Mini as in [Hack #4.02], then install Remote Buddy and you can watch any DVD you want at full quality, with all the DVD menus—no conversion required! The iPod touch and iPhone are bringing the high-end, configurable-touchscreen remote control experience into the mainstream.

Hack 10.06:

Make Your iPhone or iPod touch Talk

When you have no one left to call, use Festival-Lite to make your iPhone talk to you. With the utilities in this hack, you can add a text-to-speech engine to your phone, allowing you to turn text into speech! This can be implemented in an existing app or used on its own for various comedic or practical purposes. To get started teaching your phone how to talk, fire up Cydia [Hack #1.04] to find and install the Festival-Lite and Erica Utilities packages (and Mobile Terminal, if you don’t have that yet). See Figure 10-29. Festival is a port of a Unix-based TTS engine, and the Erica Utility is called play, a simple command-line player of audio files. 274

iphone hacks

HACK # 10.07 Figure 10-29. The two utilities and how to find them

As these are just command-line utilities, that’s all the setup you need. Once those are installed, connect to your iPhone via SSH [Hack #9.04]. Type in the following commands, with your own content where necessary: flite "This is text to speech" -o filename.wav play filename.wav

You can see what that would look like in Figure 10-30.

Figure 10-30. iPhone ventriloquism

If all went well, you should be hearing your iPhone or iPod touch say the sentence in its new voice. You can even do this directly on your iPhone [Hack #9.05] by connecting to your phone (server IP 127.0.0.1) as the user “mobile” and typing the same commands as shown previously.

Hack 10.07:

Copy and Paste Between Applications

Clippy (and friends) add copy and paste to the iPhone and iPod touch. Copy and paste. Until iPhone OS 3.0, it was the most glaring feature missing from Apple’s otherwise killer device. It’s present on practically every other smartphone on the market, and has infinite applications of convenience, as any journeyman computer user has discovered. So why go without it on a portable master communication device? The Clippy application gives us the copy and paste that iPhone OS 1.x/2.x owners had been clamoring for. Clippy is available from Cydia [Hack #1.04].

chapter 10 - Copy and Paste Between Applications

275

Once it’s installed, Clippy morphs the dragging text cursor movement present in all editable text boxes into a text highlighting tool. Tapping and dragging over a section of text highlights it. To bring up the commands for Clippy, go to the numbers and symbols page of the keyboard (the one reached via the “.123” button in the bottom left). The command buttons will be along the top of the keyboard, as in Figure 10-31.

Figure 10-31. The command buttons for Clippy

Copying a phrase adds it to Clippy’s “Stack,” which is there so that you can copy and paste multiple things at a time. You can use it to keep a list of things you type frequently, saving keywords or things such as email addresses or simple stock SMS messages. The stack is shown in Figure 10-32. As can be expected, you can drag and delete the items, just like you would on any other list.

Figure 10-32. The Stack: tap an item in it to paste it where your cursor lies

Clippy will work between most applications that support text entry. It has a few quirks, but it’s the next best thing to the official Apple copy and paste mechanism. With Clippy, your efficient communication device is a little more efficient—unless you use it for something like Figure 10-33.

276

iphone hacks

HACK # 10.08 Figure 10-33. The time-wasting aspect of Clippy in action

Hack 10.08:

Download YouTube Videos Instead of Streaming With MxTube, you can store YouTube videos on your phone. The default iPhone YouTube application is useful, but lacking. It lacks access to your YouTube account, and the ability to download videos that you watch frequently. (Admittedly, YouTube itself lacks this feature.) The MxTube application by MxWeas (www.mxweas.com) lets you download videos from YouTube in high quality (for example, off the Wi-Fi in your office) and then watch them later (for example, on your flight to Jamaica, when you get away from your office). It’s so simple once it’s implemented that you’ll wonder how you ever went without it. MxTube is available from Cydia [Hack #1.04]. With MxTube, you can even force YouTube to serve you up Wi-Fi-quality video over EDGE or 3G. In Figures 10-34 through 10-36, you can see me finding a video, downloading it, and finally watching it in high quality—and this is off of the slower EDGE cellular network.

Figure 10-34. A choice for video files

chapter 10 - Download YouTube Videos Instead of Streaming

277

Figure 10-35. Download one or more videos at once

Figure 10-36. No buffering and no waiting!

Hack 10.09:

Acquire New Media with dTunes

Stream and download songs, videos, and torrents to your iPhone or iPod touch. Is an obscure song that you want immediately not available from the iTunes Store? Do you want to share a YouTube video with your off-the-grid friend who lives beyond the reach of any cell signal or Wi-Fi? Or do you just want to make the most out of your unlimited data plan by filling the “phone tubes” with multigigabyte torrent files? dTunes solves all those problems. It works as a portal to different media search websites, allowing you to download files from them easily.

Music The music download section uses www.seeqpod.com (Figure 10-37) to trawl the Internet in search of downloadable MP3s.

278

iphone hacks

HACK # 10.09 Figure 10-37. Downloading a song with dTunes

Video The video tab uses www.tinytube.com, a mobile-friendly frontend for YouTube to access videos. You can either stream them or download them (Figure 10-38).

Figure 10-38. Downloading a movie with dTunes

Torrents dTunes allows you to download BitTorrent files from any of the popular torrent websites. Just use the browser to search for a torrent you want to download, and download the file.

dd

For the torrent downloading to work, you’ll need both Enhanced Ctorrent and Mobile Terminal. Both of these are available from Cydia [Hack #1.04].

Go to Browse and click on the torrent file you just downloaded to prepare it for downloading through the command line. Now go into Mobile Terminal and type ./gettorrent. If you get an error, make sure that you went into dTunes on the Browse tab and tapped the torrent you wanted to download. More information is in dTunes itself, as shown in Figure 10-39.

chapter 10 - Acquire New Media with dTunes

279

Figure 10-39. More information about torrenting, with a helpful diagram straight from dTunes

When your torrent is done downloading (and you’re done seeding), open up Mobile Terminal again and input the command Q. That will quit the torrent app. If the files you downloaded are compatible media files, you can view them in dTunes under Browse. Now your iPhone or iPod touch is free to download the world.

Hack 10.10:

Back Up Your Jailbroken Apps

With AptBackup, you can protect your jailbroken app library from firmware updates. One major inconvenience with jailbreaking is that after a new firmware update comes out and is made completely safe and jailbroken, the unofficial apps you have installed are still erased after installing it. It’s a painful process trying to remember each app and reinstall them one by one, but fortunately AptBackup exists to take care of all that. When you press the Backup button in AptBackup, it creates a list of all the jailbroken apps you’ve downloaded and saves them as part of your backup package, so that when you back up in iTunes (Figure 10-40), they will be saved as well.

Figure 10-40. Backing up

280

iphone hacks

HACK # 10.10 So when you do install the firmware update and restore from backup (Figure 10-41), that list gets put back onto your phone.

Figure 10-41. Restore from Backup

Then you just have to reinstall AptBackup from Cydia (after jailbreaking your phone again, of course) and hit the Restore button to reinstall them all. The caveat with this program is that it doesn’t back up settings or anything added as a result of those apps (downloaded movies, and the like), but anything downloaded from Cydia is reclaimed. That includes, for example, WinterBoard skins. Fortunately, many settings for jailbroken apps get saved during regular syncing anyway. You should still check each application you use (e.g., Cycorder) to see whether there’s data, recorded media, or other information that hasn’t been saved. Backups are always your friend. This utility definitely helps those who rejailbreak with every iPhone firmware release.

chapter 10 - Back Up Your Jailbroken Apps

281

11

Development Hacks When Objective-C was chosen to be the primary development language for Nextstep, no doubt its reflective features and dynamic late-bound messaging system were cited as significant advantages. Although the language’s quirky syntax is a turn-off for some, its uneasy marriage between a Smalltalk-inspired object model and the raw low-level power of C is what gives the language its own unique strengths. That Objective-C heritage, carried through as Nextstep, became Mac OS X, and more recently spawned the iPhone OS. How ironic that this powerful dynamic language also helped to thwart Apple’s efforts to lock down the iPhone. Dynamic languages with reflection data compiled into their binaries are unusually vulnerable to reverse-engineering. All that metadata, so instrumental to runtime binding and reflective analysis, is also visible to anyone who can decipher your compiled binary format. So when the iPhone Dev Team [Hack #2.06] set themselves to the task of creating an iPhone SDK, Objective-C’s reflective metadata made the job a whole lot easier. The first part of this chapter will show how far you can go with Unix scripting: using command-line tools to build solutions and wrapping them in push-button applications. The next section will show you how to take advantage of the iPhone APIs—both their developer-friendly features and their hacker-friendly internals. We’ll explore some of the development environments that you can use, and how to customize them for your own needs. And along the way, you’ll learn about some handy tools and techniques for your iPhone hacking and development arsenal.

Hack 11.01:

Turn Command-Line Scripts into iPhone Apps

You can write complex utility applications for the iPhone in almost any scripting language. Because Mac OS X is a Unix operating system, the bountiful riches of Unix programming are available on the iPhone. If you’re familiar with any command-line programming tools, from languages like C to the dozens of scripting languages such as Python and Ruby (available on Cydia), Java, and even shell programming, you can write utility applications that perform useful functions, and wrap them in a push-button icon on your iPhone.

282

iphone hacks

HACK # 11.01

Writing Scripts The first step to writing a script, as opposed to a full-blown iPhone application, is to SSH [Hack #9.04] into your phone. If you’ve mounted your iPhone in the filesystem [Hack #9.06], then you can edit text files more easily. At the command line, you’ll find a familiar set of Unix shell tools. Some useful packages to install can be found in Development, Networking, Java, and Scripting under “Sections” in Cydia. You should browse around and search for the tools that you’re most comfortable with. In any event, you’ll need to install a variety of useful command-line utilities from Cydia. Core Utilities A key set of GNU Unix shell utilities: gawk An implementation of the awk tool for manipulating text sed A tool to edit text streams using patterns gzip File compression utility inetutils Includes a command-line FTP utility, ping, and telnet nano A command-line text editor that’s easier to use than vi netatalk Support for the Apple File Protocol; also contains a very useful timeout command for watching runaway scripts rsync A bandwidth-conservative network backup utility network-cmds Contains traceroute and netstat, both useful for network debugging shell-cmds Gives you the time, which, and killall commands, that are useful for script debugging Erica’s Utilities A collection of great command-line tools (more info at http://ericasadun.com/ftp/EricaUtilities) SQLite v3 An application that can manipulate the database used by the phone chapter 11 - Turn Command-Line Scripts into iPhone Apps

283

OpenSSH and bash are required. Both should be installed by default when you jailbreak the phone [Hack #1.03].

Hello World First, let’s get our feet wet. SSH into your iPhone [Hack #9.04] and log in as root (default). Now create a test script. (# represents the root prompt, which is where you type commands. In these examples don’t type the #. Another thing to look out for is ^D. Instead you should press Control-D. Don’t type ^D literally.) # cat > test.sh echo "Hello World" ^D # chmod 777 test.sh # ./test.sh Hello World #

We just created a file using the cat command; it’s a bit easier to use a command-line text editor such as nano, which you can invoke with: # nano test.sh

Figure 11-1 shows the nano editor in action.

Figure 11-1. The nano editor in action

As mentioned in [Hack #9.06], you can edit text files from your computer by mounting the iPhone filesystem, if you prefer.

Backup Locally Now let’s test a more useful script. Perhaps you want to back up your call log? It’s located here: /private/var/mobile/Library/CallHistory/call_history.db

284

iphone hacks

HACK # 11.01 You can make a one-line script using the gzip and date commands to make a time-stamped backup. Create a file called calllogbackup.sh with: gzip -c /private/var/mobile/Library/CallHistory/call_history.db > \ /private/var/mobile/Library/CallHistory/call_history_`date +%Y%m%d_%H%M%S`.db.gz

Now you can test this backup: # chmod 777 calllogbackup.sh # ./calllogbackup.sh # ls -l /private/var/mobile/Library/CallHistory/ total 136 -rw-r--r-- 1 mobile mobile 101376 Feb 15 12:17 call_history.db -rw-r--r-- 1 root

mobile

36619 Feb 15 12:46 call_history_20090215_124637.db.gz

Back Up to a Server In [Hack #9.04] we showed how to upload a file to a server from your iPhone. We’ll build on that now by creating a time-stamped backup of your call log and uploading it to the server. Edit calllogbackup.sh and replace its contents with the following (changing the username and domain to match your system): backup=/private/var/mobile/Library/CallHistory/call_history_`date +%Y%m%d_%k%M%S`.db cp /private/var/mobile/Library/CallHistory/call_history.db $backup echo backing up call_history.db to $backup.gz gzip $backup echo uploading $backup.gz to the server scp $backup.gz

:~/

Now test it: # ./calllogbackup.sh backing up call_history.db to /private/var/mobile/Library/CallHistory/call_ history_20090215_170737.db.gz uploading /private/var/mobile/Library/CallHistory/call_history_20090215_170737. db.gz to the server call_history_20090215_170737.db.gz

100%

36KB

35.8KB/s

00:00

Great! We’ve got a one-line script that backs up the call log. You could run this from MobileTerminal [Hack #9.05] on your phone, but it would be more convenient to have an iPhone application simply run your script.

Wrap the Backup in an Application We don’t want to do a bunch of development (we’re scripting here), so we’re going to take an existing application, copy it, and put our script inside. On the iPhone, applications are stored in bundles, which are simply folders, usually with an .app extension. We’ll use the application respring [Hack #11.12] (Figure 11-2) from Cydia as our template. respring is also how we’ll make our new application show up in SpringBoard.

chapter 11 - Turn Command-Line Scripts into iPhone Apps

285

Figure 11-2. respring

SSH over to your iPhone and you’ll be able to see Respring.app in /Applications/: # cd /Applications # ls AppStore.app/

FieldTest.app/

MobileSMS.app/

Stocks.app/

BootNeuter.app/

Insomnia.app/

MobileSafari.app/

TVOut.app/

BossPrefs.app/

Installer.app/

MobileSlideShow.app/

Weather.app/

Calculator.app/

Maps.app/

MobileStore.app/

Web.app/

CallBackup.app/

MobileAddressBook.app/

MobileTimer.app/

YouTube.app/

CallLog.app/

MobileCal.app/

PdaNet.app/

biteSMS.app/

Cycorder.app/

MobileMail.app/

Podcaster.app/

iCallBR.app/

Cydia.app/

MobileMusicPlayer.app/

Preferences.app/

siax.app/

DemoApp.app/

MobileNotes.app/

Respring.app/

Documents/

MobilePhone.app/

ScreenSplitr.app/

Make your own app bundle using the Respring.app bundle: # cp -R Respring.app/ CallBackup.app # cd CallBackup.app # ls -l total 124 -rw-r--r-- 1 root staff 97332 Feb 15 17:19 Default.png -rw-r--r-- 1 root staff -rw-r--r-- 1 root staff

778 Feb 15 17:19 Info.plist 6770 Feb 15 17:19 icon.png

-rwxr-xr-x 1 root staff 13616 Feb 15 17:19 respring*

Inside the bundle are four files. If you’ve mounted your iPhone on your computer, you can “Show Package Contents” (Figure 11-3) on CallBackup (Figure 11-4) to see what’s inside. On Windows, just open the directory. • • • •

286

iphone hacks

Default.png is the image you’ll see when you launch the app. Info.plist defines the name of the application. icon.png is the icon that shows up in SpringBoard. respring, in this case, is the executable.

HACK # 11.01 Figure 11-3. Show package contents

Figure 11-4. Contents of CallBackup

The minimum necessary changes are to replace the executable and edit the text-based plist. Copy your calllogbackup script into the CallBackup.app directory and delete the file named respring: # cp ~/calllogbackup.sh . # rm respring

Next, edit the plist using a plist editor or a text editor [Hack #11.02]. (On a Mac, choose “open hidden” to open the plist from inside an application bundle, or drag the files out of the bundle to edit them.) Minimal necessary changes are bolded:

CFBundleCopyright <string>Perceptive Development CFBundleDevelopmentRegion <string>English CFBundleExecutable <string>calllogbackup.sh CFBundleIdentifier <string>com.perceptdev.calllogbackup CFBundleInfoDictionaryVersion <string>6.0 chapter 11 - Turn Command-Line Scripts into iPhone Apps

287

CFBundlePackageType <string>APPL CFBundleSignature <string>???? CFBundleVersion <string>0.1

We need to run respring to make our new application appear in SpringBoard. Let’s run it (Figure 11-5). As there’s no application name in this plist, the application name that shows up in SpringBoard will be the name of the bundle/folder, without the .app: CallBackup.

Figure 11-5. Resprung CallBackup

Set the Icon and Picture To distinguish your application, you can change the background picture and icon. Simply copy the Default.png and icon.png from the CallBackup.app directory to your computer, edit them, and put them back in the application bundle/folder (Figure 11-6). We’re editing the files in Adobe Photoshop, then choosing “Export for Web and Devices” to create small PNG files of less than 100K in size.

Figure 11-6. Editing Default.png and icon.png in Adobe Photoshop

When these have been edited and added to the bundle, you can run respring again to see them (Figure 11-7). 288

iphone hacks

HACK # 11.01 Figure 11-7. Final CallLogBackup icon and screen (AT&T bill courtesy of David Winer)

Handle Timeouts Gracefully One thing you will quickly learn is that if you write bad scripts, your script-based iPhone application will hang. You can terminate it by holding down the Home button for a while [Hack #2.02], but better yet, you can put some error handling in your script. A useful utility called timeout, found at /usr/bin/timeout, is installed as part of netatalk [Hack #9.06]. # /usr/bin/timeout Usage: /usr/bin/timeout [-s signal] seconds program [args]

You can use a numerical signal, or one of these (if you don’t supply a signal, it defaults to TERM):

HUP

INT

FPE

KILL BUS

QUIT ILL

TRAP ABRT IOT

URG

STOP TSTP CONT CHLD TTIN TTOU

XCPU XFSZ VTALRM

SEGV SYS

PIPE ALRM

PROF WINCH INFO

EMT TERM IO USR1

USR2

If you put timeout 5 before another command, it will run that command, and then kill it in 5 seconds if it hasn’t already completed. For example: # timeout 5 cat > hang Terminated #

(cat > hang waits for input and would therefore go on forever until the user entered Control-D). So to improve our backup script, we’ll add timeouts to hold our backup script. We’ll copy our working script to backup.sh: # cp calllogbackup.sh backup.sh # chmod 777 backup.sh

Then we’ll replace the contents of calllogbackup.sh with the following, which uses `dirname $0` to find the directory of the script that was launched by the application:

chapter 11 - Turn Command-Line Scripts into iPhone Apps

289

script=`dirname $0` /usr/bin/timeout 60 $script/backup.sh

The bundle should now contain the following files: # ls -l total 108 -rw-r--r-- 1 root staff 94206 Feb 15 20:09 Default.png -rw-r--r-- 1 root staff

809 Feb 15 17:46 Info.plist

-rwxrwxrwx 1 root staff

334 Feb 15 20:27 backup.sh*

-rwxr-xr-x 1 root staff -rw-r--r-- 1 root staff

21 Feb 15 20:27 calllogbackup.sh* 2267 Feb 15 20:04 icon.png

Now we know that our app will eventually quit (after 60 seconds) if it doesn’t succeed.

Display Result Codes As our final trick, we’d like to know whether our last backup succeeded. In the Erica Utilities is a program called “badge” that puts a label on the application icon. You can try it out—you should get the result shown in Figure 11-8: # badge badge application-name (badge) # badge CallBackup hello attempting to badge com.perceptdev.calllogbackup

Figure 11-8. Badge

To find out what badge to put on our backup application, we need to know whether our backup succeeded. We’ll add several more lines to check the success of our script using the script variable $?, which should contain a zero (0) if our upload was successful. We’ll also add a line to delete any files that are left over from the backup process. The final contents of backup.sh are (new lines in bold):

290

iphone hacks

HACK # 11.02 backup=/private/var/mobile/Library/CallHistory/call_history_`date +%Y%m%d_%H%M%S`.db cp /private/var/mobile/Library/CallHistory/call_history.db $backup echo backing up call_history.db to $backup.gz gzip $backup echo uploading $backup.gz to the server scp $backup.gz

:~/ if [ $? = 0 ] ; then echo "yes" /usr/bin/badge CallBackup Yes else echo "no" /usr/bin/badge CallBackup No fi rm /private/var/mobile/Library/CallHistory/call_history_*

The results of a successful (left) or failed (right) backup are shown in Figure 11-9.

Figure 11-9. Indicating script results with an application badge

You can find the code and applications listed in this hack at www.perceptdev.com/labs/ iphonehacks.

Hack 11.02:

Edit Mac OS X Property Lists (plists)

You can edit iPhone configuration settings stored in property lists. The basic way to change many settings on iPhone is to edit property lists, or plist files. Often they’re stored in an easy-to-edit text format, but sometimes they’re stored in a smaller binary format. To edit a plist file, you need to copy the file from your iPhone [Hack #1.05], or mount your iPhone on your computer [Hack #9.06]. If you’re using Windows and not using a shell, then just copy the file over to your computer using your preferred method. For this example, we’re going to edit a common iPhone preference file by copying it to our desktop using scp in a terminal program on Mac OS X:

chapter 11 - Edit Mac OS X Property Lists (plists)

291

$ scp

:/User/Library/Preferences/com.apple.Preferences.plist . com.apple.Preferences.plist

100%

214

0.2KB/s

00:01

(You’ll need to replace 192.168.1.109 with your iPhone’s IP address.) If you’ve installed the developer tools on Mac OS X, there is a program in /Development/ Application/Utilities/ called Property List Editor. For binary plists such as com.apple.Preferences. plist, this is the only way to edit the file. If you’ve done registry editing on a Windows PC, the concept is similar; preferences are stored in hierarchical lists of labeled data. You can see the com.apple.Preferences.plist file being edited in Property List Editor in Figure 11-10.

Figure 11-10. Property List Editor

Tweaking a Property List As an example of changing a feature, we’re going to enable emoji—Japanese emoticons for chat— by adding a preference key. Click Add Item and add a key called KeyboardEmojiEverywhere, make it a boolean, and check the box next to it (Figure 11-11). Next, change KeyboardLastChosen to emoji.

Figure 11-11. Enabling emoji with Property List Editor

292

iphone hacks

HACK # 11.02 Once you’re done, copy it back to the iPhone (you can type the command all on one line, but you must omit the backslash, \). Also be sure to replace 192.168.1.109 with your iPhone’s IP address: $ scp ~/Desktop/com.apple.Preferences.plist \

:/User/Library/Preferences/com.apple.Preferences.plist 100%

244

0.2KB/s

00:00

Editing on Non-Mac Platforms If you’re on Windows, Linux, or the iPhone itself, you won’t have Property List Editor. But there are still some solutions. There is a command-line utility called plutil that is part of Erica’s Utilities [Hack #11.01], and can convert back and forth between binary and text formats. You can convert the .plist you want to edit to XML format, edit it in the text editor of your choice (even on the iPhone), then convert back to binary for use. It overwrites the original file, but nondestructively; you can convert it back. To do this, you need to learn the syntax of plist files, but they’re not too hard to figure out. To convert a binary .plist to XML format for editing, type this in the Terminal on the iPhone: # plutil -cxml1 /User/Library/Preferences/com.apple.Preferences.plist Converting /User/Library/Preferences/com.apple.Preferences.plist to XML

Here are the contents of /User/Library/Preferences/com.apple.Preferences.plist:

KeyboardAutocapitalization1KeyboardAutocorrection1KeyboardCapsLock1KeyboardEmojiEverywhere

<true/>

KeyboardLastChosen

<string>emoji

KeyboardPeriodShortcut1UISuspendedSettings

To convert an XML plist file to binary so that the iPhone will recognize it: # plutil -cbinary1 /User/Library/Preferences/com.apple.Preferences.plist Converting /User/Library/Preferences/com.apple.Preferences.plist to binary

chapter 11 - Edit Mac OS X Property Lists (plists)

293

If you want to edit binary plist files on Windows, you can find Windows-based plist editing utilities such as pledit.exe (http://iphone.cazisoft.com/?p=569, Figure 11-12) and Plist Editor for Windows (www.ipodrobot.com, Figure 11-13).

Figure 11-12. pledit.exe

Figure 11-13. Plist Editor for Windows

Hack 11.03:

Create Periodic Tasks that Run in the Background Your iPhone and iPod touch can execute programs on a schedule or when triggered by certain events. Every operating system has a method of running “daemon” tasks in the background, as well as running scheduled tasks. If you want to turn an iPhone into a simple webcam, upload your position to a web server, or automatically back up some of your iPhone files to the cloud, you’ll need to know how to schedule tasks on Mobile Mac OS X. On Unix/Linux, the rc.d scripts, inetd, and cron systems run startup scripts, network services, and recurring tasks, respectively. On Microsoft operating systems, the Windows registry enumerates 294

iphone hacks

HACK # 11.03 Services and Scheduled Tasks, both of which can be managed by control panels of the same name. On Mac OS X, and thus on the iPhone, these functions are gathered together under a system managed by launchd.

Getting to Know launchd Naturally, background tasks, like background processes, are not a user-accessible feature of the iPhone without jailbreaking. Once you’ve jailbroken your iPhone or iPod touch, you can SSH in or mount the filesystem, and take a look at the various launch system-wide daemons and per-user agents. Apple provides decent documentation on launchd: •

• •

http://developer.apple.com/technotes/tn2005/tn2083.html provides an excellent overview and good definitions of terms. http://tinyurl.com/launchd2 describes how to create a launchd plist file. http://tinyurl.com/launchd documents the launchd plist file structure, which lists the paths in Table 11-1.

Table 11-1 launchd paths, from the launchd.plist(5) man page

/System/Library/LaunchDaemons

Mac OS X system-wide daemons

/Library/LaunchDaemons

System-wide daemons provided by the administrator

/System/Library/LaunchAgents

Mac OS X per-user agents

/Library/LaunchAgents

Per-user agents provided by the administrator

~/Library/LaunchAgents

Per-user agents provided by the user

LaunchDaemons are run during boot, and LaunchAgents run after a specific user logs in. While technically /System/Library/ is reserved for the system, you can put your launchd scripts in there and they will work. In this hack, we’ll store them in /Library/LaunchDaemons, just because it’s less crowded in that directory. You can connect to your iPhone and check out the existing LaunchDaemons: $ cd /System/Library/LaunchDaemons $ ls com.apple.AOSNotification.plist com.apple.graphicsservices.sample.plist com.apple.AddressBook.plist

com.apple.iapd.plist

com.apple.BTServer.plist

com.apple.itunesstored.plist

com.apple.CommCenter.plist

com.apple.locationd.plist

com.apple.CrashHousekeeping.plist

com.apple.mDNSResponder.plist

com.apple.DumpBasebandCrash.plist

com.apple.mDNSResponderHelper.plist

com.apple.DumpPanic.plist

com.apple.mediaserverd.plist

com.apple.MobileFileIntegrity.plist

com.apple.mobile.lockbot.plist

com.apple.ReportCrash.DirectoryService.plist

com.apple.mobile.lockdown.plist

com.apple.ReportCrash.Jetsam.plist

com.apple.mobile.obliteration.plist

com.apple.ReportCrash.SafetyNet.plist

com.apple.notifyd.plist

com.apple.ReportCrash.SimulateCrash.plist

com.apple.powerlog.plist chapter 11 - Create Periodic Tasks that Run in the Background

295

com.apple.ReportCrash.plist

com.apple.securityd.plist

com.apple.SCHelper-embedded.plist

com.apple.stackshot.server.plist

com.apple.SpringBoard.plist

com.apple.syslogd.plist

com.apple.aslmanager.plist

com.apple.tcpdump.server.plist

com.apple.chud.chum.plist

com.apple.update.plist

com.apple.chud.pilotfish.plist

com.apple.usbptpd.plist

com.apple.configd.plist

com.jft.pn.plist

com.apple.daily.plist

com.saurik.Cydia.Startup.plist

com.apple.dataaccess.dataaccessd.plist

com.saurik.afpd.dns-sd.plist

com.apple.datamigrator.plist

net.sourceforge.netatalk.afpd.plist

com.apple.fairplayd.plist

org.iphone-dev.yellowsn0w.plist

Creating a Recurring Task with launchd launchd provides for both background-service daemons and repeating tasks; they differ only in how you write the plist. The easiest way to see how this works is to create a simple script and run it. For this example, we’ll assume you have Erica’s Utilities installed (using Cydia), so you can invoke the play command. Connect to your iPhone and type: $ /usr/bin/play /System/Library/Frameworks/UIKit.framework/Tink.aiff

You should hear a “tink” sound. If so, create a text file called com.perceptdev.tink.plist (either run nano on the command line, or create the file on your computer and copy it over) and enter the following script, which you can download from www.perceptdev.com/labs/iphonehacks.

DisabledLabel

<string>com.perceptdev.tink

ProgramArguments

<array>

<string>/usr/bin/play

<string>/System/Library/Frameworks/UIKit.framework/Tink.aiff

<string>

RunAtLoad

<true/>

StartInterval10WatchPaths

<array/>

296

iphone hacks

HACK # 11.03 Save this file in /Library/LaunchDaemons/. Now load it into launchd by running the following command: launchctl load /Library/LaunchDaemons/com.perceptdev.tink.plist

You should now hear a tink every 10 seconds. Hurray! You’ve created a background task. To turn off the task, unload it: launchctl unload /Library/LaunchDaemons/com.perceptdev.tink.plist

Protect Your Tasks with Timeout As mentioned in [Hack #11.01], the /usr/bin/timeout utility acts as a monitor to kill a hung or runaway process. If a background task ever hangs, launchd may not run it any more. Thus, your recurring task must be responsible for shutting itself down without hanging. We’ll put a timeout before our task (as shown in bold):

DisabledLabel

<string>com.perceptdev.tink

ProgramArguments

<array>

<string>/usr/bin/timeout

<string>3

<string>/usr/bin/play

<string>/System/Library/Frameworks/UIKit.framework/Tink.aiff

<string>

StartInterval10WatchPaths

<array/>

Save this file in /Library/LaunchDaemons/. Now load it by running the following command: launchctl load /Library/LaunchDaemons/com.perceptdev.tink.plist

Make sure you hear your tink every 10 seconds again. If you don’t, verify that the exact /usr/bin/ play command you have in the script works on the command line. Try launching the launchd script again manually. Then, you can test if it comes up automatically on reboot. Power down your phone, power it up, and listen. The tink sound should start after the phone fully boots.

chapter 11 - Create Periodic Tasks that Run in the Background

297

As before, you can turn it back off with: launchctl unload /Library/LaunchDaemons/com.perceptdev.tink.plist

Debugging launchd scripts If you’re testing many different versions of your script, it’s sometimes easier to put all the commands in a script in /var/root/ and call this script in your launchd task. So we’ll put in this:

DisabledLabel

<string>com.perceptdev.tink

ProgramArguments

<array>

<string>/var/root/tink.sh

<string>

StartInterval10WatchPaths

<array/>

If your script isn’t working correctly, you can do rudimentary debugging by adding print statements to a log file you create. This is done by “echoing” into your logfile., as shown in /dev/ root/tink.sh: echo starting script >>/var/root/debug.log date >>/var/root/debug.log /usr/bin/timeout 3 /usr/bin/play /System/Library/Frameworks/UIKit.framework/Tink.aiff

Don’t forget to make tink executable: # chmod 777 /var/root/tink.sh

Then you can check out your logfile: # cat debug.log starting script Mon Feb 16 22:04:19 PST 2009 starting script Mon Feb 16 22:04:29 PST 2009 starting script

298

iphone hacks

HACK # 11.03 Mon Feb 16 22:04:39 PST 2009 starting script Mon Feb 16 22:04:49 PST 2009 #

While developing and testing scripts, you may want to set a high update frequency, such as once a minute, and then look in the filesystem to read your logfile to see how things are going. Once you have your script working how you want it, you may want to monitor it for a few days to make sure that it survives phone reboots, phone calls, and various other conditions. A simple way to know whether your script is running is to have it play a unique sound whenever it runs. You can upload any sound you want to into /var/mobile/Media/ and use Erica’s play utility to play it from your script: /usr/bin/timeout 3 /usr/bin/play /var/mobile/media/Unique.aiff

When you hear your sound, you know your script has at least run. If your script ever stops running inexplicably, chances are that the script, or one of the commands in it, has hung. To check this out, type the following: launchctl list | grep name of your launchd without the plist at the end

such as: # launchctl list | grep com.perceptdev.tink -

com.perceptdev.tink

If the result starts with a dash -, you’re fine. But if the process is hung, it will have a process ID as the first number: # launchctl list | grep com.perceptdev.tink 679

-

com.perceptdev.tink

You can kill this process, and the script should unstick and start working again. You should also then add any appropriate /usr/bin/timeout commands to your script, or figure out why it’s hanging, to prevent this in the future. Here’s the kill command: # kill 679

Easy launchd Plist Editing This hack showed you how to edit plists. However, if you’re still learning the launchd syntax, there is an easy graphical utility available for Mac OS X called Lingon (http://tuppis.com/lingon) by Peter Borg (Figure 11-14). It can be used to view the many example launchd plists on your Mac, and create valid plist files for your iPhone.

chapter 11 - Create Periodic Tasks that Run in the Background

299

Figure 11-14. The Lingon plist editor

After you’ve added the basic functions that you want performed and specified how you want to trigger them, you can click Expert Mode on the bottom left of Lingon’s editing panel to see the plist XML that it produces (Figure 11-15).

Figure 11-15. Lingon Expert Mode

This output code can be easily copied and pasted into a plist file for your iPhone or iPod touch.

300

iphone hacks

HACK # 11.03

Create Periodic Backups with launchd The backup script from [Hack #11.02] can be triggered on a schedule so that you don’t have to remember to run your backup program. In this example, create /var/root/backup.sh, and add timeouts in it for safety: backup=/private/var/mobile/Library/CallHistory/call_history_`date +%Y%m%d_%H%M%S`.db /usr/bin/timeout 10 cp /private/var/mobile/Library/CallHistory/call_history.db $backup /usr/bin/timeout 20 gzip $backup /usr/bin/timeout 60 scp $backup.gz

:~/

Create the appropriate repeating task in Lingon (Figure 11-16). Select a 24-hour repeat (you could also choose “every day” from the specific date checkbox and choose a time of day), and check the box to run it at login.

Figure 11-16. Creating a repeating task in Lingon

Then save the resulting plist file as /System/Library/LaunchDaemons/com.perceptdev.callhistory. plist:

Label <string>com.perceptdev.callhistory ProgramArguments

chapter 11 - Create Periodic Tasks that Run in the Background

301

<array> <string>/var/root/callarchive.sh

RunAtLoad <true/> StartInterval 86400 WatchPaths <array> <string>/private/var/mobile/Library/CallHistory/call_history.db

Load it by running the launchctl load command: launchctl load /System/Library/LaunchDaemons/com.perceptdev.callhistory.plist

Or simply reboot your phone. Either way, you’ll now get an automatic backup of your call history whenever it is modified.

Hack 11.04:

Manipulate iPhone Application Databases

You can back up and modify built-in iPhone application databases with SQLite. Although preferences are usually stored in plists, many iPhone apps store their application data in SQLite database files (Figure 11-17).

Figure 11-17. call_history.db

SQL, or Structured Query Language, is a database language developed by IBM in the early 1970s. It is now the de facto, universal standard for client-server databases worldwide. SQLite is a highperformance, local database engine that stores its data in files on disk or flash memory. It has 302

iphone hacks

HACK # 11.04 become a standard tool for storing relational data on Mac OS X and is used by most of the built-in iPhone applications, such as Mail, Calendar, iTunes, Phone, and Address Book. Here is a list of some of the SQLite databases and their locations on the iPhone: /Private/var/mobile/Library/CallHistory/call_history.db /Private/var/mobile/Library/AddressBook/AddressBook.sqlitedb /Private/var/mobile/Library/AddressBook/AddressBookImages.sqlitedb /Private/var/mobile/Library/Calendar/Calendar.sqlitedb /Private/var/mobile/Library/Notes/notes.db /Private/var/mobile/Library/SMS/sms.db

A basic tutorial on using sqlite3, a command-line utility for manipulating sqlite databases, can be found at www.sqlite.org/sqlite.html.

Learning SQL If you’ve ever worked with databases such as Oracle, Microsoft SQL, or MySQL, SQLite is very similar. It has a smaller subset of commands, because it isn’t designed to serve files to millions of users over a network—just to a few programs on the same machine. SQL is a simple language used to ask for information from a database. If you haven’t worked with SQL before, it’s okay—it’s not that hard to pick up. For beginners, there’s Head First SQL, by Lynn Beighley (O’Reilly, 2008). A good programmer's book on SQLite in particular is Inside SQLite, by Sibsankar Haldar.

Running SQLite Even if you don’t know SQL, you can follow these steps, and you’ll pick up most of what’s going on. First, install sqlite3 in Cydia [Hack #1.04] Then log into your iPhone [Hack #9.04] and type: # sqlite3 /private/var/mobile/Library/CallHistory/call_history.db sqlite>

You can type .help to get a list of commands. .table shows you what tables (in SQL, data is organized into tables, which are tabular collections of data consisting of rows and columns) are in this database, and .dump will give you several screens worth of information showing the SQL commands to create the whole database, tables, and data entries from scratch. The most common command you’ll need is select, which shows you the contents of tables. You can see what is in each table with select * from

: sqlite> .tables _SqliteDatabaseProperties

call

sqlite> select * from _SqliteDatabaseProperties; call_history_limit|100 timer_last|420 timer_outgoing|220260 timer_incoming|193800 timer_all|414060 timer_lifetime|414060 timer_last_reset|0 data_up_last|101.5009765625 chapter 11 - Manipulate iPhone Application Databases

303

data_down_last|1145.037109375 data_up_all|31542.912109375 data_down_all|299468.912109468 data_up_lifetime|31542.912109375 data_down_lifetime|299468.912109468 data_last_reset|0 _ClientVersion|3 _UniqueIdentifier|571721D0-F5CA-46F7-A3D1-CC73EB96EE22 __CPRecordSequenceNumber|2644 sqlite> select * from call; 1351|3232544000|1231266047|0|5|3480 1352|3235541000|1231266052|0|5|4280 1353|13233812000|1231266056|0|5|2975 1354|32390880000|1231266061|0|5|2906 1355|3233812000|1231266066|0|5|2975 1356|3235541000|1231266071|0|5|4280 1357|3235541000|1231266266|0|5|4280 1358|8189088000|1231266271|0|5|2906 1359|8189088000|1231266452|0|5|2906 1360|3105541000|1231266456|0|5|4280 1361|3105541000|1231266461|0|5|4280 ...

Browsing Databases with a GUI Application If you’ve mounted your iPhone drive on your computer’s filesystem [Hack #9.06], or copied a .db file over to your computer, then you can use a SQLite file browser such as MesaSQLite (www.mesamysql.com/?realmesa_home) to view the iPhone files (Figure 11-18).

Figure 11-18. Opening a Database File

You can view all the entries of the call database by selecting call from the drop-down table menu, and clicking Show All (Figure 11-19). This executes the SQL query, shown in the bottom left, which is select * from call.

304

iphone hacks

HACK # 11.04 Figure 11-19. Select * from call in MesaSQLite

Extending the iPhone Call Database The example SQL command showed us all the entries of the call database. Unfortunately, the iPhone trims this database to the last 50 entries, including dropped calls. Thus, for some heavy phone users, the log goes back only a day or two. The following hack extends the call record so that it keeps all the calls. Even though the iPhone keeps trimming, this hack will save the deleted entries and reinsert them into the call table. Here’s how it works:

1. 2. 3.

Each time the /private/var/mobile/Library/CallHistory/call_history.db is changed, trigger a script using launchd [Hack #11.03]. In this script, create a new table called archive if it doesn’t already exist, and copy all the new call records to archive. If desired, copy the full archive table back over the call table, so that the whole list can be displayed.

The SQL commands to accomplish these steps are straightforward. You can download these scripts from www.perceptdev.com/labs/iphonehacks. Here is the file that you should save as /var/root/callarchive.sh: # This script and associated SQL commands are released to the Public Domain # this script runs a sqlite command to copy the most recent entries from the # 'call' table to the 'archive' table # the call_history.db must already have an 'archive' table with the same # structure as 'call' # you can do this by typing #

sqlite3 /private/var/mobile/Library/CallHistory/call_history.db

#

create table if not exists archive as select * from call;

# timeout 20 sqlite3 \ /private/var/mobile/Library/CallHistory/call_history.db < \ /var/root/archive.sqlcmds timeout 5 play /var/mobile/Media/Tock.aiff chapter 11 - Manipulate iPhone Application Databases

305

Here is the file that you should save as /var/root/archive.sqlcmds: create table if not exists archive as select * from call; insert into archive select * from call where ROWID > (select max (ROWID) from archive) and ROWID <= (select max (ROWID) from call); insert into call select * from archive where ROWID < (select min (ROWID) from call);

To test the script, simply run it at the command line. You should hear the “tock” sound: # ./callarchive.sh

This will create the archive table (if it does not already exist) and make a backup of whatever is currently in your call history. Now, dial/hangup/dial/hangup a few times (you don’t have to wait for the call to connect) to stuff the database full of entries. Now run it again: # ./callarchive.sh

Because the phone application may already have a cache of what is in the call database, you may need to run it, then hold the Home button for 10 seconds to force quit it [Hack #2.02]. Then launch it again. Now, if you dial a few numbers beyond the limit (50) you can scroll down and see that they are being retained. You can create a background task [Hack #11.03] that is triggered whenever /private/var/mobile/ Library/CallHistory/call_history.db is modified to make sure that the archive table captures every call that is made. Then, even if the iPhone trims the main call table, archive will have a complete record. To do this, create a launchd file and put it in /Library/LaunchDaemons: Here is the file that you should save as /Library/LaunchDaemons/com.perceptdev.callarchive.plist:

Label <string>com.perceptdev.callarchive ProgramArguments <array> <string>/var/root/callarchive.sh StartInterval 86400 WatchPaths <array> <string>/private/var/mobile/Library/CallHistory/call_history.db

306

iphone hacks

HACK # 11.05

RunAtLoad <true/>

This script launches based on three different triggers: at load (RunAtLoad), every 24 hours (StartInterval), and whenever the database file is written to (WatchPaths). To test it, you can dial a number and hang up quickly. Whenever you finish a call, the phone should “tock.” You may need to occasionally restart the phone application as described previously to get the list to show up, but each tock means that the archive is being faithfully kept. You should be able to scroll a very long call list. ——Damien Stolarz & Devananda Van Der Veen

Hack 11.05:

Sync Your Call Log with iCal on Mac OS X

Using a script on your Mac OS X machine, you can import your call log records into iCal. If you’re one of those people who like to keep track of everything in your calendar program, you may have wondered why the iPhone doesn’t put the call log right into iCal. The call log database is stored separately and differently than the calendar database on the phone, and there’s nothing there to keep them in sync. One way to approach the problem would be to create a script that runs on the phone and does all the necessary syncing. However, someone has already tackled the problem.

iphonelogd There’s a great Ruby script developed by Jamie Hardt available at http://code.google.com/p/ iphonelogd called calllog2ical.rb. It accomplishes the laudable goal of importing call records from an iPhone backup by iTunes, into iCal, on Mac OS X 10.5. This approach is great, but it has some drawbacks. First, if you have a lot of different devices that sync to your Mac, then the script doesn’t always know which one to grab the call records from. Second, and through no fault of the script, the iPhone tends to delete records much more frequently than many people sync to iTunes. The elements of a solution, however, have already been discussed. [Hack #11.02] showed you how to back up the call log. And [Hack #11.03] showed how to do it on a schedule. If you’ve implemented those hacks, your call log should be very long and safely stored somewhere. Now we just need to import it! To import the call logs, we’re going to:

1. 2. 3.

Upload the Address Book and call logs from the iPhone to a web server. Download the Address Book and call logs from the server to the Mac. Import them into iCal.

chapter 11 - Sync Your Call Log with iCal on Mac OS X

307

iPhone to Server In order to properly show the name of who called—instead of just the phone number—it’s necessary to get a copy of /Private/var/mobile/Library/AddressBook/AddressBook.sqlitedb from the iPhone as well. We’ll update our script from [Hack #11.01] to add uploads for both these files. For cleanliness, we’ll create two files: callarchive.sh and callarchive-do.sh. That way we can call them from an app, or a task, and the parent script will take care of timeouts. Here’s what needs to go into /var/root/callarchive.sh (edit with nano [Hack #11.04] or on your computer): /usr/bin/timeout 60

/var/root/callarchive-do.sh

Here is the contents of /var/root/callarchive-do.sh: # This script and associated SQL commands are released to the Public Domain # this script runs a sqlite command to copy the most recent entries from # the 'call' table to the 'archive' table # the call_history.db must already have an 'archive' table with the same # structure as 'call' # you can do this by typing #

sqlite3 /private/var/mobile/Library/CallHistory/call_history.db

# create table if not exists archive as select * from call; sqlite3 /private/var/mobile/Library/CallHistory/call_history.db < \ /var/root/archive.sqlcmds scp /private/var/mobile/Library/CallHistory/call_history.db \

:~/ scp /private/var/mobile/Library/AddressBook/AddressBook.sqlitedb \ :~/

The callarchive-do.sh script can be launched manually from an application [Hack #11.01] or a launchd task [Hack #11.03]: # ./callarchive.sh call_history.db

100%

103KB 103.0KB/s

00:00

AddressBook.sqlitedb

100% 1093KB 182.2KB/s

00:06

dd

In our testing, the call log was over 100K and the Address Book was over a megabyte—not something you want to upload from an original iPhone over EDGE. If you’re going to automate this in a launchd task, you may want to upload the Address Book once, and then only upload the call_history.db on a schedule.

Server to Mac You’ll need to choose a working directory on the Mac to which you’ll download the files and run your import script. Copy the relevant files down to your Mac with the following commands in Terminal: # scp

:~/call_history.db . Password: ******** call_history.db

100%

103KB 103.0KB/s

00:00

# scp

:~/AddressBook.sqlitedb . Password: ******** AddressBook.sqlitedb

308

iphone hacks

100% 1093KB

1.1MB/s

00:00

HACK # 11.05 If you don’t want to bother with copying it to the server first, you can simply copy it directly from your iPhone to your computer. However, as our earlier hacks made a convenient way to back it up to the server, you could automate the rest of the task and have the call records in iCal automatically.

Import to iCal The only parts of the original icalllog2ical.rb Ruby script that have been changed are the pieces that load and extract the call log database from the iPhone backup. The other parts that do the import and iCal feeding are unmodified. Our modifications to calllog2ical2.rb, change the script so that it loads the call log and Address Book from the same directory it’s run in, instead of from the iPhone backups made by iTunes. The modified script can be found at www.perceptdev.com/labs/iphonehacks. The original import script and our modifications are licensed under GPL v2. Put the databases you just downloaded and calllog2ical2.rb in the same folder. Then launch the iCal application and create a new calendar named “iPhone.” You will use this command as the argument to calllog2ical2.rb. Go back to terminal, and run the import. $ ./calllog2ical2.rb iPhone

You can switch back to iCal and watch as it fills in the calls (Figure 11-20). Depending on the length of your call log, this will take several minutes. The script is somewhat smart about starting where it left off last. You should not add any other entries to this calendar manually, as that will confuse the script.

Figure 11-20. Call logs in iCal

chapter 11 - Sync Your Call Log with iCal on Mac OS X

309

The script has some additional options: you can exclude specific phone numbers (“I didn’t call her, I swear!”) and eliminate zero-duration calls (like calls that failed, or accidental dial/hangups). You can see some of the options when you run the script with the help (-h) argument: $ ./calllog2ical2.rb -h Usage : calllog2ical.rb [options] [CALENDARNAME] -v, --verbose

Run verbosely

-l, --leave-db

Leave the extracted working sqlite files in their temporary location instead of deleting.

-e, --exclude-number NUMBER

Exclude calls from the given number

-x, --exclude-file EXCLUDE-FILE

Exclude calls listed in EXCLUDE-FILE. EXCLUDE-FILE should contain a whitespaceseparated list of telephone numbers.

-f, --force DATE

Force calendar to be updated with all call log events since DATE, deleting all events after DATE before going through the normal read process

-0

Don't copy events with zero duration. (Incomplete/Unanswered calls)

-h, -?

Show this message.

If you zoom into specific days, you can see where all that time goes. Maybe it’s time to sign up for an unlimited all-you-can-talk plan (Figure 11-21).

Figure 11-21. Call log database visualized in iCal by week

Figure 11-22 shows a day view. You can uncheck the calendar titled “iPhone” if you want to remove all the clutter (Figure 11-23). You can stop making so many phone calls if you really want to remove all the clutter.

310

iphone hacks

HACK # 11.06 Figure 11-22. Day view

Figure 11-23. Call log off

Hack 11.06:

Choose Between the Apple SDK and Open Tools for iPhone Development

Despite what Apple would like you to believe, the official SDK is not the only game in town. So you have an idea for an iPhone application. One of the first decisions you must make as a would-be iPhone developer is which SDK to use. This decision has lasting implications, because it determines what frameworks you can access, what features your application is allowed to have, and ultimately who can install it on their phones. It seems unfair to have to make such an important decision so early, particularly if you’ve never written an iPhone application before. Fortunately, you can reverse your decision later—nothing is set in stone—but as you’ll see, switching SDKs may require some significant code changes if you chapter 11 - Choose Between the Apple SDK and Open Tools for iPhone Development

311

don’t plan ahead. Also, using the Apple SDK requires you to sign a licensing agreement. So it’s important to make the right choice early on.

The Contenders The iPhone open toolchain (generally just referred to as the “toolchain”) was the first development kit released for the iPhone. It was pieced together from a variety of open source projects, with a lot of modifications and original code written by a dedicated group of coders and hackers. Apple didn’t make it easy—once the phone was jailbroken [Hack #1.03] to allow access to the filesystem so that files could be added and modified, there was also the problem of Apple’s modified compiler based on an outdated version of gcc, for which the modified source code had not yet been released. Herculean efforts were required to circumvent these problems and create working tools (for further details you can read Jay “saurik” Freeman’s detailed account of the process at www.saurik.com/id/4). The result of all this work is a suite of tools that are both incredibly powerful and incredibly complex. Apple’s iPhone SDK entered beta testing in March 2008, after the open toolchain had enjoyed months of success, and many thousands of iPhones were already jailbroken and running applications. The SDK features a variety of useful tools and a fairly simple install process, as well as a thorough set of documentation. The streamlined APIs are more accessible and easier to understand. But the SDK also imposes strict limits on developers, and deliberately restricts access to some of the more powerful aspects of the iPhone’s firmware. Choosing one development environment over the other is not a clear-cut decision, and there are several factors to consider.

Cost The open toolchain is open source and completely free. The iPhone SDK is also free to download, but you are required to sign up (for free) as a Registered iPhone Developer, which means you are subject to the terms of Apple’s developer agreement. The Official SDK also does not allow you to test applications on the phone without a code signing certificate. Apple provides these certificates only to members of the iPhone Developer Program. (The program also provides other benefits, including distribution on the iTunes App Store and access to prerelease firmware.) Membership costs $99 for the Standard program. The Enterprise program, targeted at businesses wishing to develop proprietary in-house software, costs $299.

Documentation When the open toolchain was first reverse-engineered from the iPhone firmware, all of the iPhone’s internal frameworks were exposed. The API headers that were generated were functionally complete but lacking in documentation, and some of the original names and data types could not be recovered from the compiled binaries. Because the iPhone OS is based on Mac OS X, some of the APIs were already familiar to developers on the Mac platform. But many frameworks specific to the iPhone, even though they are available through the toolchain, are difficult to use, because they simply haven’t been fully explored and documented. This issue was particularly problematic before the release of Apple’s official SDK, because the Version 1.x firmware was significantly different from 2.x. Its APIs were not intended for public use, so they were not as carefully designed as one might hope, and sometimes difficult to grasp based solely on the class interfaces. Even one of the most essential frameworks, UIKit (which provide the

312

iphone hacks

HACK # 11.06 GUI for iPhone apps) was not completely understood in firmware Version 1.x, and documentation was sparse. Developers wishing to use any but the most common classes were in for a struggle. With the release of the iPhone SDK, official documentation is now available for the public frameworks and classes in firmware v2.x. (However, many of these classes have changed significantly from their 1.x counterparts, including those in the UIKit framework, so the SDK offers little insight for those targeting older 1.x firmware versions.) For developers targeting jailbroken 2.x firmware via the toolchain, the SDK documentation can be quite helpful—at least as a starting point.

Features and Limitations The SDK includes an iPhone simulator (Figure 11-24), and an integrated debugger that works with apps running on either the simulator or the device. The toolchain has neither. However, if you are targeting the Version 2.x firmware, you may still be able to test your toolchain code on the simulator, as long as the code uses mainly the unrestricted frameworks of the SDK. (Some of the frameworks are too difficult to simulate without cell phone hardware, and are therefore understandably absent.) The toolchain can also be integrated into Xcode, allowing toolchain apps to be debugged on jailbroken devices using the integrated debugger.

Figure 11-24. The iPhone Simulator

The iPhone SDK also comes with Interface Builder, a graphical layout application for user interfaces. It is a powerful tool, though it has a bit of a learning curve for those accustomed to a fully integrated interface designer like the one in Microsoft’s Visual Studio. Using it can be a great boon to those who plan to distribute through the App Store, but those who are considering unofficial distribution should beware. The toolchain has no way to compile Interface Builder’s .xib files, which forces you to use Xcode for at least part of the build process. If you’re contemplating the

chapter 11 - Choose Between the Apple SDK and Open Tools for iPhone Development

313

option of targeting jailbroken phones, you should therefore consider creating your user interface programmatically (Apple’s APIs are quite capable in this regard) rather than using Interface Builder. The iPhone SDK exposes many of the frameworks that are present on the iPhone, but several frameworks are private, and third-party (that’s you) applications are forbidden to use them. Some examples include: • • • • • •

BluetoothManager—interface to the iPhone’s Bluetooth hardware Celestial—a streaming audio framework CoreSurface—access low-level graphics buffers directly CoreTelephony—interface to the iPhone’s cellular telephony hardware LayerKit—layer-based graphics compositing WebKit—the web browsing and rendering framework that powers Safari

There are workarounds that can expose these APIs—usually by splicing [Hack #11.15] toolchain headers into the SDK—but Apple has stated that applications that use private frameworks will not be distributed on the iTunes App Store. To be fair, many of these functions can be accessed at a higher level of granularity through public frameworks, and some developers will not miss them. Still, certain applications requiring fine-grained control of these functions will be severely hampered by this restriction. Many classes and even individual class methods have also been left out of the official headers, even when the overall framework is made public. Some of these hidden objects and methods can also be accessed by splicing toolchain headers into the SDK, or by using the class-dump tool to generate new headers. It is not clear whether Apple would prohibit this use of undocumented classes and methods in public frameworks, nor is it clear whether they are capable of detecting it. Google, for example, has successfully published an application that clearly uses undocumented functions— but not prohibited ones—and so far Apple has not chosen to remove the app from the store. Toolchain applications are completely unrestricted, and can use any known framework—but again, many of the private frameworks are poorly documented. Official SDK applications are also subject to certain technical restrictions due to Apple’s sandboxing security model. Applications have limited file access rights, except in their own dedicated folders. They cannot access the iTunes library content stored on the phone, or any data stored by other applications, unless a public framework exposes it (like the Address Book). They are also unable to run as background processes; the application is forced to close when it loses focus. All of these are deliberate design choices and Apple is unlikely to reverse their decision in the future. Toolchain applications running on jailbroken phones have no such restrictions. There are additional terms-of-use restrictions on the App Store that some developers will find onerous: •

Applications cannot use excessive bandwidth, especially on the cellular network (the precise threshold which constitutes “excessive” is not known). Applications cannot execute other program code (e.g., emulators, VMs, and other runtime engines like Flash or .NET).

Also note that Apple’s licensing terms may conflict with certain open source licenses. For example, Apple’s code signing policies would seem to violate the terms of GPLv3. If you plan to bring an open

314

iphone hacks

HACK # 11.06 source project to the iPhone and distribute it through official channels, you should make sure that your open source license is compatible with Apple’s terms. As for toolchain applications, Installer.app and Cydia distributors will probably accept any kind of application except malware. A final note on software license issues: although the binary tools in the toolchain, such as the compiler and linker, are based on open source projects and are compliant with their licenses, it is important to realize that the header files may not be so unencumbered. Current versions of the toolchain depend on headers that must be copied from the official SDK, which means they are subject to licensing restrictions. For now it is common practice to ignore this hiccup, but in order to achieve greater legitimacy, the open toolchain development community may need to put some effort into reverse-engineering their own header files, using tools like class-dump-x, so that the Apple SDK can be avoided entirely if so desired.

Distribution Developing an application for the Official iPhone SDK gives you the opportunity to distribute your application through the iTunes App Store. If you choose to charge for your application, Apple’s cut of the purchase price is 30%; free apps are distributed without any additional charge. (This is in addition to the $99 membership fee for the Developer Program.) In return, you get to use Apple’s considerable digital sales and distribution muscle, including payment processing, server hosting for your app’s installation bundle, and a store listing, all handled for you automatically. Your widest possible audience encompasses anyone who has firmware Version 2.0 or later—an audience that is increasing over time as the iPhone 3G is being sold with 2.x preinstalled. Toolchain applications on 1.x firmware were most often distributed through Installer.app. Since the debut of 2.0 jailbreaking methods, a new premier player in this space has emerged, the aforementioned Cydia, which is a user-friendly front end for Debian’s APT package manager. The two differ in their implementation of packaging schemes, list formats, and other details, but the essential purpose and features are similar. Because many software jailbreaks load one or both of these installers onto the phone automatically, this is the best-known and most popular method for obtaining third-party applications outside of the App Store.

Lag Time Developer Program members targeting the Official SDK have access to prerelease versions of the firmware and matching development kits before the firmware is made available to the public. This means that you have a chance to update your application to take advantage of the new firmware, and hopefully you can have the new version ready for release as soon as the firmware goes public. Toolchain developers, on the other hand, must wait for the new firmware to be jailbroken (which may take some time after the public release) and for the toolchain to be updated with any new APIs. Clever hackers may find ways to gain access to the upcoming firmware and prepare for it ahead of time, but unless you can access the prerelease firmware yourself and test against it, you may still experience significant lag time before you can release your updated application. The lag is particularly noticeable when significant API changes occur, such as during the transition from v1.x to v2.0 firmware. It leaves toolchain developers stuck in a waiting game, knowing that new documentation and classes are available that would make their lives easier, but being unable to take advantage of those upgrades until after the firmware is released and jailbroken.

chapter 11 - Choose Between the Apple SDK and Open Tools for iPhone Development

315

On the other hand, developers who use the App Store sometimes run into a different kind of lag. Apple’s manual approval process can cause a significant delay between the time you submit your app (or an updated version of it) and the time it is accepted and made available through the store. Though Apple insists that it is making great efforts to streamline the process, there are still horror stories circulating around the Internet. The unpredictability of this phenomenon can wreak havoc with outside marketing schedules, not to mention inducing a lot of indigestion, as hapless victims anxiously await judgment from the fickle gods at Apple’s approval department.

To Each His Own Ultimately, the choice of Apple’s official SDK vs. the open toolchain is one that you have to make for yourself, based on your application’s needs and your intended audience. You may need total access to the phone’s filesystem; you may need the infrastructure of the App Store; or you may simply prefer the independent spirit of the toolchain developers. Whatever you decide, there is a whole community of iPhone users out there waiting to see what you have to offer.

Quick hack See More Device Information in iTunes The Summary screen in iTunes can be used to get more information about your device. Click on the Capacity bar at the bottom to see how many items are on the phone, the length of existing playtime, or the amount of memory used. Click on the words “Software Version,” “Serial Number,” or “Phone Number” at the top to see additional technical information. This can be an easy way to get the phone identifier if you need to send it to a developer.

316

iphone hacks

——George Dean IV

Hack 11.07:

Develop iPhone Applications with Apple’s SDK

The most comfortable way to develop iPhone apps is with Xcode. Apple’s SDK is based on the Xcode suite, which is the primary development kit for Mac OS X. Under the hood, the Xcode IDE is simply invoking Apple’s version of the GCC compiler. Regardless of whether you’re developing for the open toolchain or the App Store, there is strong incentive to use these official tools, particularly for simulation and debugging.

Downloading and Installing the SDK If you don’t have the SDK already, you can get it from Apple at http://developer.apple.com/iphone. You’ll have to register for a developer account and agree to some licensing terms, but it’s free of charge. The SDK is packaged as a disk image file (.dmg), which Finder will mount as a virtual disk. To install the SDK, launch the package installer located in the virtual disk (Figure 11-25).

Figure 11-25. Apple’s iPhone SDK installer

HACK # 11.07 Once the SDK is installed, you will find the suite of applications and tools in /Developer/ Applications. Xcode, the main IDE, is the one you will use most often, and you’ll probably want to drag it to your Dock right away (Figure 11-26).

Figure 11-26. Xcode

Building the UICatalog Sample Let’s build one of Apple’s sample applications. The one we’ll use in this example is UICatalog, which is a demonstration of just about every built-in user interface element that’s available on the iPhone, as well as some of the configuration options that you can use to customize their appearance and behavior. It has also been ported to the iPhone open toolchain already, and can be built on both Linux [Hack #11.10] and iPhone [Hack #11.11], so it will be our universal example for all three platforms. In Xcode, open the Documentation window by choosing Help→Documentation from the menu (or you can press Command-Option-Shift-?) (Figure 11-27).

Figure 11-27. Documentation window

In the Documentation window, type UICatalog into the search box and press Enter. The first entry in the results list should be the UICatalog sample application. Choose that result, and scroll down the page to the “Download Sample” links (Figure 11-28).

chapter 11 - Develop iPhone Applications with Apple’s SDK

317

Figure 11-28. Download sample

Alternatively, you could visit the iPhone Dev Center at http://developer.apple.com/iphone and download the sample directly from the website. You can get the sample code as either a DMG or a ZIP archive. Download and unpack the contents to a new folder. One of the files in the archive is an Xcode project file called UICatalog.xcodeproj. Open this. The Xcode project window will appear (Figure 11-29).

Figure 11-29. Xcode project window

Open the Build Configuration drop-down list in the upper-left corner of the project window, and make sure that the Active SDK is Simulator—iPhone OS 2.2, or whichever the most recent SDK version is (Figure 11-30).

318

iphone hacks

HACK # 11.07 Figure 11-30. Choosing the Active SDK

Now you can click Build and Go (or press Command-Enter), and the project will be compiled and launched in the iPhone Simulator (Figure 11-31).

Figure 11-31. The iPhone simulator

The iPhone simulator is a convenient tool for testing your applications before installing them on the actual device. It has faster turnaround than a full deployment to the phone (which can take several seconds to complete over USB), so it is well suited to testing rapidly iterated changes that require many rebuild cycles. It also has no provisioning requirements, so it is easier to set up than a real deployment. However, the simulator is not an emulator, so the performance characteristics and memory footprint of your simulated application will bear little resemblance to the actual conditions on the device. Also, although most of the frameworks function identically in both the simulator and the real firmware, there are some major and minor differences (in both public and private APIs) that will cause problems if you depend too heavily on the simulator for testing. Ultimately, you will need to go beyond the simulator and deploy your application to a real device.

chapter 11 - Develop iPhone Applications with Apple’s SDK

319

Install the UICatalog Sample on the Device In order to install your applications to the iPhone with the Apple SDK, you must have a valid provisioning profile. This profile combines your code-signing identity with a list of unique device identifiers that determines which devices are allowed to install and run your application. In order to create a provisioning profile, you must be a member of one of Apple’s paid developer programs, either Standard ($99) or Enterprise ($299). Creating this profile is a lengthy process that is spelled out in the How To tab of the Provisioning section of the Developer Program Portal, accessible at http://developer.apple.com/iphone. If you don’t have a provisioning profile, there are ways to work around the requirement, as described in [Hack #11.08]. Once the provisioning situation is taken care of, you’re ready to build and install the UICatalog sample to the device. You simply need to select Device → iPhone OS 2.2 (or the most recent SDK version) as the active SDK from the Build Configuration drop-down list. Then click Build and Go to build, install, and launch the application on your iPhone. ——George Dean IV

Hack 11.08:

Self-Sign Your SDK Projects

You can build and deploy SDK apps to your jailbroken phone with your own code certificate. With the Apple SDK, you usually have to provision a device to test your code on it. If you have SDKbased code working and you want to test it on your jailbroken iPhone or iPod touch, you can selfsign the code and skip the provisioning. The iPhone uses three basic security restrictions to keep unauthorized code from running on the platform. The first restriction, the chroot jail, keeps the user from making any significant modifications to the filesystem, and it is overcome by jailbreaking [Hack #1.03]. The second restriction, code signing, ensures both file integrity and authentication of the program author’s identity. Jailbreaks eliminate the authentication check, but they leave the integrity checking intact (because the integrity information is easy to generate and the checks for it are widespread and difficult to disable). The third restriction, provisioning, determines whether the application is authorized to run on a particular device. This restriction is overcome by modifying the MobileInstallation framework.

dd

You need to install and run at least one app from the App Store before you try this, or these workarounds may fail. It can be a free or paid app—it just needs to be from the real App Store.

Code Signing with Self-Signed Certificates There are two main ways to self-sign your code. When using Xcode, the simplest method is to set a self-signed certificate as your signing identity. Xcode will use this certificate to sign your executables, with the result that all the integrity-checking information is properly generated but the rest of the signature is invalid. On a jailbroken phone, this is fine, because the rest of the signature will be ignored anyway.

320

iphone hacks

HACK # 11.08 To generate a self-signed certificate, you can follow the steps in Apple’s guide at http://developer. apple.com/documentation/Security/Conceptual/CodeSigningGuide/Procedures/chapter_3_ section_2.html. When creating the self-signing identity, take careful note of the name you used when creating the certificate, because you’ll need it in the next step. Next, open up your Xcode project in order to set the new code signing identity. With the project open, go to Project→Edit Project Settings. Find the setting called Code Signing Identity: Any iPhone OS Device, click the value field, and select Other from the menu that pops up. Now change the value to the exact name you used when creating the self-signing identity (Figure 11-32), and hit OK to save the new setting. This should configure the project to use the new identity.

Figure 11-32. Self-signing certificates in Xcode

You may have to restart Xcode or reboot your computer after these changes.

Code Signing with ldid Self-signed certificates solve the code signing problem only when you’re running Xcode. For other platforms, there is a program called ldid that is used to create fake code signing data from scratch. You can get it from Cydia under the name Link Identity Editor. To sign an unsigned binary, invoke it with the -S parameter: $ ldid -S <program file>

Most Makefiles for iPhone projects already invoke ldid in this way during the install phase. If you’re creating your own Makefile for a project, or porting a project from another platform, you’ll probably want to add this step in order to save yourself some typing, otherwise you would have to invoke ldid yourself after every make.

Disable Provisioning in Xcode The automated install process on the iPhone relies on provisioning profiles to determine whether the application is authorized. Because Xcode is designed to use this automated process, it requires

chapter 11 - Self-Sign Your SDK Projects

321

a valid provisioning profile when building an app for the device. You can disable this requirement, however, by editing a certain property list [Hack #11.02]: /Developer/Platforms/iPhoneOS.platform/Info.plist

Be sure to back up the original before you make any changes. Open the file in a text editor or plist editor and add the highlighted entries shown here:

NATIVE_ARCH <string>armv6 PLIST_FILE_OUTPUT_FORMAT <string>binary PROVISIONING_PROFILE_ALLOWED <string>NO PROVISIONING_PROFILE_REQUIRED <string>NO SDKROOT <string>iphoneos2.2

Save it, and restart Xcode. You should be able to build your project in device mode without setting a provisioning profile.

Disable Provisioning Checks on the iPhone When iTunes or Xcode attempts to automatically install an application, the phone uses the MobileInstallation framework to verify that the device is authorized to run the application based on the provisioning profile. Disabling this check, so that any application can be installed by iTunes or Xcode, requires a modification to the MobileInstallation binary file. Fortunately, iPhone developer javacom of http://iphonesdkdev.blogspot.com provides an automated patcher that can be installed through Cydia. First, add the correct server to your Cydia source list: Once the source is added to Cydia, you can install the package named MobileInstallation Patch, which will apply the patch and disable the provisioning checks. A new MobileInstallation patch must be issued for each firmware release, but so far the updates have been prompt. You can check for the latest news at the blog URL given earlier in this hack, or at this post on the Hackint0sh forums [Hack #2.06], which is kept up to date with the latest MobileInstallation patch announcements: http://hackint0sh.org/forum/showpost. php?p=340693&postcount=14. ——George Dean IV

322

iphone hacks

HACK # 11.09

Hack 11.09:

Manually Install Applications

The Xcode “Build and Go” method isn’t the only way to install your applications on the iPhone. Once you’ve built your application (or if you’ve manually downloaded an app from someone else), you’ll need some way to get it onto the phone. If you’re using the Official SDK, and all your provisioning ducks are in a row, this would be a job for Xcode or iTunes. But there is an alternative to this automated process, using a Unix tool called scp. First, find out what your phone’s IP address is. You can get this from the built-in Settings app, or from another control panel app like BossPrefs.

dd

Your computer and your iPhone should be on the same Wi-Fi network. You’ll also need to make sure that SSH is installed and enabled on your phone, as scp uses the SSH protocol to communicate with the phone. You can check this in BossPrefs as well.

Next, open a Terminal window on your computer, and navigate to the parent directory that contains the .app bundle you wish to install. Now it’s time to invoke scp (which is short for “secure copy”). The command looks like this: $ scp -r YourApplication.app

:/Applications/

where YourApplication.app is the name of your application bundle, and 192.168.0.101 is the IP address of the phone. Just substitute the correct values for your application and phone. Be ready to type in the root password, which by default is alpine [Hack #9.04]. Once the copy is complete, the final step is to reinitialize SpringBoard (the iPhone application launcher) so that it will detect your application and show its icon. You could turn off your phone and reboot it, but that takes some time. Fortunately you can soft-reset SpringBoard with respring, which you can invoke from the command line or through the UI. For details on how to install and use respring, see [Hack #11.12]. Once SpringBoard restarts, your application icon should be visible, and you’re ready to run. Although it’s important to understand these steps in principle, usually this process will be automated in your Makefiles, when you invoke the install target on your development computer: $ make install

The install target typically uses scp to copy the files, ldid to fake the code signing, and finally respring to restart SpringBoard. But if make install fails, or you need to customize your Makefile, you’ll need to know what the steps are. ——George Dean IV

chapter 11 - Manually Install Applications

323

Hack 11.10:

Use a Virtual Machine for Building iPhone Apps You can develop jailbroken apps for the iPhone, even if you don’t own a Mac. Apple’s official SDK requires Mac OS X; developers who exclusively use other platforms are out of luck. But there are still ways to do the bulk of your coding on other platforms. For example, you could use a portability layer to hide the platform-specific details, like developer Chad W. Randall of Just Kissed Games. He wrote his own framework to simulate the iPhone on Windows so that he could develop in the familiar environment of Microsoft Visual Studio. (The resulting game, Beseigement, can be found in the App Store; the official website is at www.beseigementgame.com.) Still, even with a portability framework, you must ultimately move the code over to a Mac in order to build the app with the SDK. But if you’re thinking of creating apps with the open toolchain, the possibilities are practically endless. The open source tools that make up the toolchain are highly portable and can be built on a variety of platforms, including Linux. If you want to work through the entire process of building the toolchain on Linux, you can find a complete walkthrough on Jay “saurik” Freeman’s website at www.saurik.com/id/4. However, this is a slow and painstaking process, involving many of the sort of command-line machinations that Unix geniuses consider expedient, but that baffle the rest of us. There is a much easier solution, if you have the ability to run virtual machines. (VMware has some excellent free tools for both Linux and Windows at www.vmware.com.) Some clever toolchain developers have created preconfigured virtual machines that contain a working toolchain running on a Linux guest OS. As these are updated frequently, links change. An Internet search for “vmware iphone toolchain” will reveal sites like http://hackint0sh.org/forum/showthread.php?t=26548, which has instructions and links for obtaining one of these images as of this writing. You can also appeal to the iPhone community [Hack #2.06], which will direct you to the latest tools.

Downloading and Configuring the VM This particular VM is hosted at http://iphonefix.de. You’ll have to visit the website first to get a login/password for their FTP server—the site’s administrators have disabled anonymous access for security and performance reasons. Once you have the session-specific username and password, you can download the image by navigating to the iPhone Toolchain VMware Image. You may want to use a dedicated FTP program (Figure 11-33), as the file weighs in at more 1.2 GB, so that downloads can be resumed if they get interrupted.

324

iphone hacks

HACK # 11.10 Figure 11-33. Using an FTP program to download the toolchain

Once you have the iPhone Toolchain VMware image, launch it (Figure 11-34). It contains a command-line-only Ubuntu Linux installation. The root password is toolchain.

Figure 11-34. VMware launch screen

Next, configure networking. In VMware’s network settings, configure this machine to use shared networking (NAT) or bridged networking. You can use this command to examine your VM’s network adapters: $ ifconfig -a

Inside the guest OS, your Ethernet adapter may come up as eth0, or eth4, or some other eth device. Cloning a VMware image can cause a new device to be detected, so if you’re having trouble you can delete the file /etc/udev/rules.d/z25_persistent-net.rules (which stores the various detected Ethernet devices) and reboot, and it should let Linux find your eth0 device.

chapter 11 - Use a Virtual Machine for Building iPhone Apps

325

If your VM’s Ethernet device does not list an IP address, you can try to enable DHCP by running dhclient (Figure 11-35). If this approach successfully obtains an IP address for the network adapter, you can check it by running ifconfig again.

Figure 11-35. Running dhclient

Once you have an IP address, you no longer have to work with VMware’s screen directly—instead, you can use your favorite SSH program [Hack #9.04] on the host to connect one or more terminal sessions to the server (Figure 11-36): # ssh root@

Figure 11-36. SSH connection to the VMware Ubuntu Toolchain Server

To gain access to various codebases available online, you’ll want to install CVS. The easiest way to do so is by invoking the APT package manager that’s included with all Debian Linux distributions (Figure 11-37). # apt-get install cvs

326

iphone hacks

HACK # 11.10 Figure 11-37. Installing CVS

Building the Samples There are some goodies in the root account’s Home directory, /root. Most notable are the sample projects found in /root/SDK20PROJECTS/, where you will find: -rw-r--r-- 1 root root

1951 2008-10-19 09:46 README.txt

drwxr-xr-x 2 root root

4096 2008-12-28 09:45 respring

drwxr-xr-x 4

501 staff 4096 2009-01-04 00:10 UICatalog

drwxr-xr-x 2

501 staff 4096 2009-01-03 20:41 WinterBoard

respring, a command-line utility, will restart the SpringBoard application launcher and rebuild its cache. For further details see [Hack #11.12]. UICatalog is a sample application that demonstrates a variety of UI elements available in the UIKit framework. WinterBoard is an open source skinning application by the aforementioned Jay “saurik” Freeman, and it also serves as an example of how to combine Objective-C with C++. Unless you already have a command-line version of respring installed on your iPhone, you should build and install respring first. The other sample, UICatalog, tries to execute respring in its Makefile in order to display its application icon after installation. The easiest way to make sure that this will work is to build and install the included version of respring. The Makefiles of both respring and UICatalog have lines near the top that look like this: IPHONE_IP=192.168.0.11

You’ll need to edit the Makefile, replacing that IP address with the correct IP for your phone, so that the Makefile can automatically install the app to the correct location. If you’re not already accustomed to the popular text editors in Linux, like vim or an Emacs clone, you may find their unusual editing keystrokes rather offputting and difficult to learn. Fortunately, there are many text editors available, including my personal favorite, JOE (Joe’s Own Editor), which uses a mishmash of WordStar and Emacs key mappings. It can also emulate Emacs, WordStar, or Pico. But most importantly, it has a handy onscreen key reference. If you’re interested in installing JOE, you can once again take advantage of Debian APT: # apt-get install joe chapter 11 - Use a Virtual Machine for Building iPhone Apps

327

Once JOE is installed, you can run it to edit the Makefile: # cd /root/SDK20PROJECTS/respring # joe Makefile

Now that the IP address has been corrected, all you have to do is build and install the app: # make # make install

You can follow the same basic procedure for the UICatalog sample. Change the IP address in the Makefile, build, and install. When you install UICatalog to the phone with make install, your SpringBoard should restart and then the UICatalog icon should appear. UICatalog is a port of Apple’s sample application to this build environment. The major difference, other than adding a Makefile to support Unix-style builds, is the fact that Interface Builder files (XIB and NIB) are not used here. As Interface Builder is available only on the Mac platform, there is no way to compile the XIB source files into loadable NIB files without using a Mac. To avoid this problem, the user interface elements that would have been loaded from the NIB are instead created programmatically in this version of the app. Almost all toolchain apps create their interfaces programmatically in order to avoid Interface Builder dependencies. Even in its original form, UICatalog already creates almost all of its controls programmatically, so it provides an excellent resource for learning how to create and configure the various UI controls in your code. This version simply takes it one step further, by converting the remaining few elements that were created in the XIB.

Ready to Go You now have all the tools you need to get started developing toolchain apps in Linux. This open source software stack will enable you to explore the vast possibilities of the jailbroken iPhone platform. ——George Dean IV

Hack 11.11:

Develop iPhone Applications on Your iPhone

It’s almost poetic: build your iPhone application right there on your iPhone. The power of the iPhone’s Unix-based OS really begins to sink in when you realize that it can run gcc, and therefore build its own applications. Granted, there’s no possibility of installing an IDE, so this method isn’t likely to become an overnight sensation. But for those who feel at home on a Unix command line, there is a certain appeal to developing apps in situ.

Installing the Toolchain Installing the tools themselves is easy, because they are available as Cydia packages. You simply use the Search feature to find the proper packages and install them:

328

iphone hacks

HACK # 11.11 GCC The GNU Compiler Collection Make The standard command-line tool for dependency-based build scripts (Makefiles) Link Identity Editor (ldid) An application that simulates code signing OpenSSH (ssh) For remote terminal access Getting the appropriate headers installed is a bit more complicated. Putting together a set of headers from their original sources is a long, laborious process that involves extracting the framework headers from the iPhone SDK, reorganizing their path structure (Apple places the headers in nonstandard locations) and copying them over to the phone is detailed here: www. saurik.com/id/4. Alternatively, you may be able to get help from the community [Hack #2.06] or from someone who has already gone through the process (http://antirez.com/page/iphone-gcc-guide. html). Either way, you can install the headers to /usr/include on your iPhone.

Building an Open Source Program on the iPhone Now you have everything you need to build something, let’s try it out. Since there aren’t any sample projects included, you’ll have to download something. How about the JOE editor mentioned in [Hack #11.10]? You’ll have to edit Makefiles and other text files fairly frequently, so it might be nice to have a terminal-oriented text editor installed. This will also get you acquainted with some of the issues you may face when building other projects on the iPhone. First, you’ll need to download the source code tarball, named joe-3.7.tar.gz, from the official JOE website: http://joe-editor.sourceforge.net. Then you’ll need to copy it over to the phone and extract the contents: # scp joe-3.7.tar.gz root@

:/var/root # ssh root@ # tar xvzf joe-3.7.tar.gz # cd joe-3.7

The JOE website claims that you should be able to run three commands: ./configure, make, and make install, and that will be it. Unfortunately, that doesn’t work correctly on the iPhone platform, so there are additional steps to be taken. The first command, ./configure, runs the configure script for the project, which autodetects certain attributes of your system and creates a customized Makefile that takes your platform’s idiosyncrasies into account. But if you simply run ./configure, it will fail, because one of the tests tries to execute the output of a build. This test fails because the iPhone requires code signing, and the configure script knows nothing about code signing. The workaround is tricky to figure out but simple to perform. Fortunately, the execution check is skipped if the configure script is told that it is cross-compiling for a different platform, instead of compiling natively for the current platform. So even though we are compiling for the native platform, we just tell the script that it’s a cross-compile by explicitly specifying the --host parameter: # ./configure --host=arm-apple-darwin chapter 11 - Develop iPhone Applications on Your iPhone

329

Even though this is the same platform descriptor as the one you’re running on, the script takes us at our word and assumes we are cross-compiling. In this configuration, the script no longer attempts to execute the test program that it builds, and it should complete without error. At this point, the configure script has generated a proper Makefile, but there is one more unexpected problem with this project. JOE has built-in expression evaluation capabilities, including a lot of math functions. Unfortunately, for unknown reasons, some of the functions from the C math library math.h are missing on the iPhone. In particular, the Bessel functions, j0, j1, y0, and y1, are missing. But the source file umath.c attempts to use them, which will lead to link errors if you try to build this program in its current form. The solution is to remove all references to the missing functions. Fortunately there are only eight such references, and you can delete the entire line in each case. This makes the edit so simple that you can run it as a single command using sed, the Unix Stream EDitor: # sed -i.old '/[jy][01]/ d' umath.c

Let’s break down this command line briefly so that you’ll know what it’s doing. The first argument -i.old tells sed to edit the file in place, and back up the old version with the extension .old. The last argument, umath.c, is the name of the file that we want to edit. That leaves the second argument, '/[jy][01]/ d', which does all the work, is a sed command that will be run on each line of the file. The first part of the command is a regular expression that each line is matched against. If a line matches, then the d at the end of the command tells sed to delete the line. So sed will delete any line containing j0, j1, y0, or y1. (That also includes larger identifiers that contain these sequences, like m_j0. Fortunately, that’s what we want, in this specific case.) This example barely scratches the surface of sed. It’s a complex and rich tool, and you would be well served to learn more about it. With that fix to the source code, the project is now ready to build. The make command does the job: # make

Once you’ve built it, though, you can’t just install it right away; you need to fix the code signing problem first, or it won’t run. That’s where ldid comes in. It adds fake code signing blocks to your executable so that it will pass muster. Once it’s fake-signed, you can proceed with the install step. # ldid -S joe # make install

And that’s it! You’ve successfully built an open source project on the iPhone. You can now invoke JOE just as you would on other platforms: # joe README

You may find some of these workarounds useful in the future. The configure script issue is one that you may face once in a while, and the --host fix should work in most of those cases. And of course the ldid code-signing step has to be performed on every executable you build. (Fortunately, a lot of Makefiles for iPhone projects already include this step, so you don’t always have to type it in.)

330

iphone hacks

HACK # 11.12

Build the UICatalog Sample Now let’s try building the UICatalog sample on the iPhone. First, you should make sure you have a command-line version of respring installed, as described in [Hack #11.12], because the Makefile for UICatalog will try to invoke it. As the UICatalog sample isn’t preloaded, we’ll need to download it. An iPhone toolchain-compatible version is hosted on Google Code, but you’ll need a subversion client to get the source code. Fortunately subversion has been ported to the iPhone already. You can get it from Cydia, or install it from the command line: # apt-get install subversion

Once subversion is installed, you can check out the code using the svn co command: # cd ~ # svn co http://apiexplorer.googlecode.com/svn/trunk/UICatalog UICatalog

The source code includes three different Makefiles so that you can build the same code on Mac, Linux, or iPhone toolchains. The one we want to use is named Makefile.iphone. Let’s rename it to Makefile, so that the make command will pick it up automatically. Then it’s just a matter of running make and make install: # cd UICatalog # mv Makefile.iphone Makefile # make # make install

After the SpringBoard restarts, the UICatalog application should now be available. ——George Dean IV

Hack 11.12:

Restart Your SpringBoard to Reveal Newly Installed Applications Restarting the SpringBoard is a small but critical step in the deployment process. There are several different ways to restart your SpringBoard, through both the UI and the command line, and they each have their own merits. One application that can restart the SpringBoard is BossPrefs. Recent versions have a “Fast Respring” button on the Power management screen (Figure 11-38). Touching the button will immediately quit BossPrefs and restart the SpringBoard.

chapter 11 - Restart Your SpringBoard to Reveal Newly Installed Applications

331

Figure 11-38. BossPrefs power management screen

respring allows you to restart the SpringBoard directly from the Home screen. Just touch the respring icon (Figure 11-39) and you’re good to go.

Figure 11-39. respring ready to restart SpringBoard

Both BossPrefs and respring are available from the BigBoss source in Cydia [Hack #1.04]. When you want to automatically restart SpringBoard (such as in the install phase of a Makefile) you’ll need a command-line version of respring. There are two basic ways to approach this. One way is to download a command-line respring package, which is available from the Cydia repository at www.iphone.org.hk/apt. (If you haven’t already added that source, you’ll have to add it manually, but it contains several useful utilities discussed in this chapter.) The respring package (notice the lowercase r in Figure 11-40) installs a respring program in /usr/bin, so that you only need to type “respring” on the command line to trigger it.

332

iphone hacks

HACK # 11.13 Figure 11-40. Download respring package from Cydia (notice lowercase r)

Alternatively, if you already have BossPrefs or respring installed, you can copy the program to /usr/bin/ yourself, and avoid downloading a separate package: # cp /Applications/BossPrefs.app/Respring /usr/bin/respring

or # cp /Applications/Respring.app/respring /usr/bin/respring

Alternatively, you could make a symbolic link in /usr/bin/ instead of copying the file: # ln -s /Applications/BossPrefs.app/Respring /usr/bin/respring

or # ln -s /Applications/Respring.app/respring /usr/bin/respring

Whichever method you choose, the result is that a simple respring command will restart your SpringBoard. ——George Dean IV

Hack 11.13:

Create a UI Without Interface Builder

Though it lacks Interface Builder’s drag-and-drop simplicity, hand-coding an iPhone UI is fairly straightforward. Typical iPhone projects, including most of Apple’s sample apps, rely on Interface Builder’s NIB files for at least some portion of their UI. This presents a problem when trying to build those projects on other platforms, because Interface Builder is available only on Mac OS X. Currently the only way to overcome this is to create the desired UI elements programmatically, thereby eliminating the need for the NIB files. The UICatalog sample serves as an invaluable resource for hand-coding your UI. For one thing, most of the controls are hand-coded even in Apple’s original version of the code; and also, the sample has already been converted to be NIB-free. You can examine the changes yourself in detail, by visiting the project’s Google code repository at http://code.google.com/p/apiexplorer/source/ detail?r=17. (The NIB removal was done in revision 17, and that page shows you every edit made in that revision.) chapter 11 - Create a UI Without Interface Builder

333

A variety of changes were required in order to allow UICatalog to break free of Interface Builder. But don’t think that this only applies to projects that started out using Interface Builder; most of these steps must be fulfilled in any NIB-free application, even if it’s written from scratch. Also keep in mind that if you’re converting your UI from an existing Interface Builder XIB document, you must be intimately familiar with its contents in order to do the conversion. You either need to have the document open in Interface Builder, or attempt to decipher the convoluted XML format that makes up the XIB file itself.

Specify the Application Delegate Class The NIB file typically specifies which class should be loaded as the application delegate. When you remove the NIB, this association is lost. It’s up to you to explicitly provide the class name as a parameter to UIApplicationMain, which is called from the main function: int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

Create the Main Window and Root Views Now that you know the application delegate will be loaded properly, let’s make sure that it is fulfilling its responsibilities. In general, an object should create the UI objects it owns. That has special meaning when Interface Builder is involved, because Interface Builder allows you to attach NIB-created objects to outlets provided by your classes. When the NIB is gone, you must not only create the UI objects, but also make sure that they are referenced by the correct outlets. To determine which class should own each UI object, follow these guidelines: • •

If the object is referenced by exactly one of your classes, that class owns it. If the object is referenced by more than one of your classes, you must choose the best one to own it (usually the class that is higher in the UI hierarchy). If the object is not referenced by any of your classes, then it should be created by whatever class creates its parent object.

The application delegate class typically owns the main window and the root portions of the view controller hierarchy. The logical time to create these root UI elements is when the application first launches, which is indicated by the applicationDidFinishLaunching: method in the modified, NIBfree UICatalog: // create window window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; window.backgroundColor = [UIColor blackColor]; // set up main view navigation controller MainViewController *mainViewController = [[MainViewController alloc] init]; // create a navigation controller using the new controller navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController]; [mainViewController release]; // add the navigation controller's view to the window [window addSubview: navigationController.view]; [window makeKeyAndVisible];

In this example, the primary view controller at the root of the hierarchy is a UINavigationController. It contains a MainViewController instance as the root of its navigational 334

iphone hacks

HACK # 11.13 structure. Some applications choose UITabBarController as the primary controller; others use custom view controllers when the application is not suited to the standard navigational models of the iPhone. But whatever the right root view is for your application, this is where it gets created and added to the main window.

Create Subviews for Your Custom View Controllers This part varies greatly between projects, because it is highly dependent upon what type of subviews are needed for each custom view controller. Rather than get bogged down in the specific implementation details of the UICatalog sample, let’s focus on the key points. There are two broad categories of initialization that must take place to fully instantiate a custom view controller: data initialization, and the actual creation of subviews. When a view controller is loaded from a NIB, the data initialization typically is done in response to one of two load-time messages: initWithCoder:, the special initializer that gets called during loading from a NIB, or awakeFromNib, the notification message that is sent right after a NIB loading operation completes. But neither of these calls will be made when a new instance is created explicitly, which means any data initialization that’s buried in one of those methods must be moved to a standard initializer. The default initializer init is a good choice. The actual creation of views typically constitutes the bulk of the new code that you’ll have to write. When loading from a NIB, of course, all this is done for you; but when creating a new instance from scratch, the correct place to create subviews is in the loadView method. This is called when the view controller needs to be displayed. Finally, when the hierarchy of subviews is created, you simply need to assign the top-level parent view to the view controller’s view property. This code snippet from UICatalog’s MainViewController loadView method illustrates the creation of a simple top-level container view: UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; self.view = contentView; [contentView release]; self.view.autoresizesSubviews = YES;

By setting the autoresizesSubviews property, this view will automatically resize its contents to adjust for other screen elements like toolbars and navigation bars. Other, more specialized views are then added as subviews of this generic parent container. In this example, the only subview is a UITableView that fills its parent. Here are the key lines that accomplish that: myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; myTableView.autoresizesSubviews = YES; myTableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); [self.view addSubview: myTableView];

The initWithFrame: initializer is common to all UIView subclasses. (In this case, we’re using the class-specific initWithFrame:style:, but it serves the same function.) It allows you to set the frame coordinates of your view as you’re creating it, so that you can place it in the desired screen chapter 11 - Create a UI Without Interface Builder

335

location right from the start. You will use some variant of initWithFrame: for most of your handcoded subviews. The autoresizingMask property determines which dimensions will be adjusted when its parent tries to automatically resize it. Views intended to fill their parents should set UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight so that both width and height are adjusted. You could also allow the margins to be adjusted—that is, the distance between an edge of the subview and the corresponding edge of its parent—by specifying one or more of UIViewAutoresizingFlexibleTopMargin, UIViewAutoresizingFlexibleBottomMargin, UIViewAutoresizingFlexibleLeftMargin, or UIViewAutoresizingFlexibleRightMargin. Finally, the subview is added to the parent view by sending the addSubview: message: [self.view addSubview: myTableView];

By combining these basic ingredients—initWithFrame:, autoresizesSubviews, autoresizingMask, and addSubview:—you can create arbitrarily complex adjustable layouts for your application’s views.

Removing the NIB from Your Project Once you’ve converted all your UI elements to be created programmatically, you should go ahead and remove the XIB file from the Xcode project (if you have any intention of being able to build the project in Xcode in the future). You also need edit the Info.plist file to remove the NSMainNibFile key, which refers to the NIB file. Both the key name and the string value need to be deleted. While you have Info.plist open, you should also replace all those unexpanded variables, like ${PRODUCT_NAME} and ${EXECUTABLE_NAME}, with appropriate values for your project. Xcode fills in

these variables for you, but other build environments won’t. There are also references to IBOutlet scattered throughout the code. These are textual tags added to the code for the benefit of Interface Builder. Because IBOutlet is #defined to be an empty macro, these occurrences of IBOutlet should be harmless. But if you ever want or need to get rid of them, you can safely delete these references now that Interface Builder is no longer in use. Similarly, IBAction is #defined to be void, so you can feel free to substitute void anywhere IBAction appears.

Explore More UIKit Controls UICatalog’s wide array of programmatically created controls should be able to help guide you in creating almost anything you might find in a XIB document. I highly recommend perusing the program to familiarize yourself with all the styles and choices available. And of course the SDK documentation has more to say about UIKit than just about any other framework. ——George Dean IV

336

iphone hacks

HACK # 11.14

Hack 11.14:

Use API Explorer to Peek into Built-in Frameworks See what classes are really available on your iPhone. API Explorer is a useful utility that lets you examine all the classes in all the frameworks that it’s linked to. The prebuilt version is linked to CoreGraphics, Foundation, and UIKit. But if you download the source, you can rebuild it and link it to almost any frameworks you want! The prebuilt version of API Explorer is available from this Cydia repository: www.iphone.org.hk/apt. You’ll need to add this source to Cydia if you haven’t already done so, and then install the package called API Explorer. The icon will then appear on your SpringBoard (Figure 11-41).

Figure 11-41. API Explorer

Launching the program presents you with a list of class names (Figure 11-42). These are all the classes currently loaded by the Objective-C runtime in this program; effectively, all the classes in all the frameworks that it was linked with at build time. (For this build, that’s CoreGraphics, Foundation, and UIKit, as mentioned earlier; but as CoreGraphics and UIKit rely on other frameworks, such as QuartzCore and WebKit, they are silently linked in as well.)

Figure 11-42. Class names in API Explorer

chapter 11 - Use API Explorer to Peek into Built-in Frameworks

337

You can use the search box at the top to enter all or part of a class name, and API Explorer narrows down the results list to only the class names that contain that substring (Figure 11-43).

Figure 11-43. Filtering class names

When you select a class from the list, you will be presented with some pertinent information regarding that class: its superclass, any formal protocols it implements, its instance variables, class methods, and instance methods (Figure 11-44).

Figure 11-44. Class information

You can also click the Reference button to visit the reference page for this class on Erica Sadun’s website. Her extensive collection of class-dumped header files and cross-referenced code analysis can help you discover even more about the classes you are interested in (Figure 11-45).

338

iphone hacks

HACK # 11.14 Figure 11-45. Class reference pages

But the three frameworks linked to this build of API Explorer are just the tip of the iPhone iceberg. To explore more frameworks, you need to download the source code and build your own version. It’s designed for Xcode and the Apple SDK, so if you’re running on Linux or some other toolchainbased environment, you’ll have a bit of a porting adventure on your hands. The project is hosted on Google Code at http://code.google.com/p/apiexplorer. You can check out the code from the subversion repository at http://apiexplorer.googlecode.com/svn/trunk/ apiexplorer using your favorite subversion GUI or with this terminal command: $ svn checkout http://apiexplorer.googlecode.com/svn/trunk/apiexplorer apiexplorer

When the download completes, open the Xcode project. You’ll need to change the code signing settings: in the main menu, choose Project→Edit Project Settings. When the Project “Explorer” Info window comes up, go to the Build tab, and select your preferred code signing identity in the Code Signing section. (You can read more about code signing identities in [Hack #11.08] and [Hack #11.09].) Now you should be able to click Build and Go and successfully test the application. Once you’ve got everything up and running, you can add whatever frameworks you see fit (except for a few dummy frameworks like IOKit, which will cause link errors if you try to use them). See [Hack #11.15] to learn how to add frameworks. Even though the private frameworks don’t have headers, you can still link them to API Explorer, and the application will use Objective-C’s runtime information to explore every class in the framework. And if the framework has been class-dumped by Erica Sadun, you can jump to the online reference pages as well. ——George Dean IV

chapter 11 - Use API Explorer to Peek into Built-in Frameworks

339

Hack 11.15:

Access Private APIs

Private doesn’t necessarily mean inaccessible. Apple’s SDK only exposes a small fraction of the iPhone’s frameworks. Even in those frameworks that are public, only a tiny fraction of the classes in each framework are documented and have official header files. And in those classes for which header files are provided, only a small percentage of each class’s methods are declared in the headers. All those other classes and methods are hidden, waiting to be accessed—and you can use them in your jailbroken applications. All you need to know is how to tell the compiler about those hidden APIs. In order to tell the compiler what’s there, of course, you have to know about it yourself. You can do a simple examination with the API Explorer application [Hack #11.14], but that app does not currently display type information, such as variables or methods, so you won’t get very far that way. You’ll need a more powerful tool.

class-dump The ultimate source of hidden API information is class-dump, a utility that dumps all the type information from an Objective-C framework and creates header files for every class it finds. Some type information is lost; Objective-C does not store the static types of object references, so they all show up as the generic type id. But the type information expressed in the generated headers is complete enough to allow you to use the framework successfully. A large set of doxygen-generated reference pages, based on class-dumped headers, is maintained by Erica Sadun at her website, http://ericasadun.com. The pages for firmware Version 2.2 are found at http://ericasadun.com/iPhoneDocs220. These pages contain both annotated source code for the headers and cross-linked reference pages. The Linux virtual machine referred to in [Hack #11.11] already has a full set of class-dumped headers. For other development platforms, you can use class-dump to generate your own headers. It’s available for the iPhone and can be installed through Cydia or with the following iPhone terminal command: # apt-get install class-dump

Let’s say you want to dump the Celestial framework so you can use its media playback capabilities. At the iPhone command line, type these commands: # mkdir -p ~/dump/Celestial # class-dump -H -o ~/dump/Celestial \ /System/Library/PrivateFrameworks/Celestial.framework/Celestial # cd ~/dump/Celestial

Unfortunately, the generated headers are not perfect. They frequently start with #import "NSObject.h", which doesn’t exist, thus causing compilation errors when you try to use the

headers. You can fix this by removing these lines, because most Objective-C programs will #import NSObject.h from the Foundation framework very early in each file. The sed command to do this removal is: # sudo sed -i.old '/NSObject\.h/ d' *.h

340

iphone hacks

HACK # 11.15 You may encounter other bad header references when using these files. Be prepared to occasionally hand-edit the #import statements to get them to point to the correct locations. Now you need to place these headers in the correct location for your dev environment. For iPhone development, just move the generated files to a subdirectory of /usr/include/: # mv ~/dump/Celestial /usr/include

For the Linux toolchain, you already have a full set of headers, as mentioned earlier, but if you need to redump later (for example, if you need to update for a newer firmware version), you can replace the existing set (replace iPhoneIP with your iPhone’s IP address). At the Linux prompt type: $ cd /toolchain/sdk20/sys/usr/include/ $ mv Celestial Celestial.220 $ scp -r root@iPhoneIP:~/dump/Celestial .

If you’re using Xcode, placing the headers is a lot more complicated. Xcode relies on each version of a framework having its own dedicated folder, which contains both the binary file (for use by the linker) and the headers for that version of the framework (if they are provided). Unfortunately, this means that for Xcode to automatically pick up the headers, there must be redundant copies of the header files for each version of the framework. As of SDK Version 2.2, there are six different versions of each framework: separate copies of the frameworks are stored for simulator versions 2.0, 2.1, and 2.2, and there are corresponding copies for each version of the device firmware. Each of the six platform- and version-specific copies of the SDK build files comes with a Library folder located as follows: /Developer/Platforms/ iPhoneOS.platform/Developer/SDKs/ iPhoneOS2.0.sdk/System/Library/ iPhoneOS2.1.sdk/System/Library/ iPhoneOS2.2.sdk/System/Library/ iPhoneSimulator.platform/Developer/SDKs/ iPhoneSimulator2.0.sdk/System/Library/ iPhoneSimulator2.1.sdk/System/Library/ iPhoneSimulator2.2.sdk/System/Library/ Within each Library folder there are two folders called Frameworks and PrivateFrameworks. Frameworks contains the dedicated folders for all the public frameworks, and PrivateFrameworks contains all the dedicated folders for the private frameworks. So, for example, the framework folder for the private framework Celestial, for builds targeting the device, in Version 2.2, is found at this location: /Developer/Platforms/ iPhoneOS.platform/Developer/SDKs/ iPhoneOS2.2.sdk/System/Library/ PrivateFrameworks/Celestial.framework Finally, within each dedicated framework folder, you will find the binary file (named after the framework, in this case, Celestial) and a Headers folder, if headers are provided. Private frameworks don’t come with a Headers folder, but if you create one, Xcode will use it, just like a public framework. chapter 11 - Access Private APIs

341

So, to install the Celestial header files, you’ll need to create six Headers folders, one for each occurrence of Celestial.framework. To make things a little easier, I’ve created a bash script that installs private framework headers to all six SDK locations automatically: #!/bin/bash for PLAT in OS Simulator; do for VER in 2.0 2.1 2.2; do fwpath=/Developer/Platforms/iPhone${PLAT}.platform/Developer/SDKs\ /iPhone${PLAT}${VER}.sdk/System/Library/PrivateFrameworks/$2.framework echo "Copy to framework: ${fwpath}" cp -R $1 "${fwpath}/Headers" done done

Save that script as ~/install-framework-headers.sh using your favorite text editor. Then enable execution privileges on it: $ chmod 755 ~/install-framework-headers.sh

The script takes two arguments: the first argument is the path that you want to copy the headers from, and the second argument is the bare name of the framework. Suppose, for example, that you want to install the Celestial headers that you dumped earlier on your iPhone. First, you need to copy the headers to a local directory, then you can invoke the script to copy those files out to the six install locations. At the OS X terminal command line (replace iPhoneIP with your iPhone’s IP address): $ mkdir ~/dump $ scp -r root@iPhoneIP:~/dump/Celestial ~/dump/Celestial $ sudo ~/install-framework-headers.sh ~/dump/Celestial Celestial

Notice that you must preface the script invocation with sudo. This is because the framework directories are write-protected for nonroot users. sudo will ask for your password, and then execute the six-way copy script as root to overcome the permissions problem. If all goes well, you should have six well-placed sets of header files ready for consumption by Xcode.

Add a Private (or Public) Framework to Your Application Whether the framework you want to use is public or private, the procedure for adding it to your project is the same. On Linux and iPhone, linking to a framework is a matter of adding an additional command-line parameter for the linker. Most Makefiles use an LDFLAGS variable to store linker parameters, so adding a framework simply means adding a line like this: LDFLAGS += -framework Celestial

To add a framework in Xcode, right-click on the Frameworks folder in the project window (Figure 11-46), and choose Add→Existing Frameworks.

342

iphone hacks

HACK # 11.15 Figure 11-46. Add existing frameworks in Xcode

Use the file browser to navigate to the Frameworks or PrivateFrameworks folder. (You don’t have to worry too much about which platform- and version-specific directory you load the framework from; Xcode should automatically redirect to the correct location based on which platform and SDK version you choose in the project’s Build Configuration drop-down.) Select the dedicated folder for your desired framework, and choose Add (Figure 11-47).

Figure 11-47. Selecting a framework in Xcode

Add a Private Class to Your Application If you want to use a class from a private framework, you can just add the framework to your project and #import the appropriate header, and you’re good to go. But what if the class you want is a hidden class in a public framework? You have headers for the public classes already installed, but not for the hidden classes. There are several approaches to solving this problem. You could replace the entire set of official SDK headers for that framework with your class-dumped versions. Unfortunately, as class-dumped headers don’t have complete type specifications for a lot of message parameters and instance variables, you’ll lose some valuable information this way—not to mention that class-dump can’t retrieve C function specifications, and most C structures are either lost entirely or given arbitrarily generated names. One approach you might take is to copy just the one header file for the class you’re trying to use, and add it to the official headers. Think of it as “splicing” classes into your SDK headers. Note that

chapter 11 - Access Private APIs

343

you may also need to copy headers for the subclasses of your dumped class, if they are also hidden classes. Also keep in mind that if you’re replacing or splicing your official headers, there are multiple copies of the official headers—and you will have to modify all of them. One other option is to add the header directly to your project, and just keep a local copy with the rest of your source files. Once again, keep in mind that you may need to add subclasses as well. You also won’t be able to use the typical #import

formulation to import the file; depending on where you put it, you’ll need to use either #import "Framework/Header.h" or #import "Header.h". Also, the header itself may use incorrect paths when importing dependencies from its own framework, so you may have to tweak some import statements there as well.

Add a Private Method to Your Application If you want to call a method on a private class, you need to import the class as described earlier. But what if you want to call a private method on a class that’s already declared in the official SDK? Once again, there are a few different ways to approach this. The first option is to replace the official class header with a class-dumped version. This is just like splicing a class-dumped class into your official headers as described previously, except that this time, you’re replacing one that already exists. For one thing, you’ll have to do it in multiple places. And you’ll also be discarding a lot of valuable type information about message parameters that was provided in the official header. You could also splice the additional method declarations from the class-dumped header into the official header, creating a merged header. This gets complicated, because you will have to find all the duplicates from the class-dumped section and delete them, and they will probably be scattered throughout the list and difficult to locate. And once again, you have to copy the merged file to all the other locations. But there’s a useful hack that allows you to call a private method without modifying headers and without causing compiler warnings. Because Objective-C allows classes to be augmented through the category mechanism, you can fool the compiler into letting you call additional methods by creating a fake category. Suppose that you want to be able to set your application’s icon badge to contain some arbitrary text. You can set the badge using the UIApplication class (Figure 11-48), but the only public method for setting the badge takes an unsigned integer, which is very limiting. A little digging in API Explorer [Hack #11.14] reveals that there is a private method, setApplicationBadge:, that looks more promising.

344

iphone hacks

HACK # 11.15 Figure 11-48. Set the badge using the UIApplication class

Checking the class dump for the UIKit framework, we can see that it takes an id and returns void: - (void) setApplicationBadge:(id)fp8;

A little web searching will make you confident that the argument is supposed to be an (NSString*). Unfortunately the limited type information stored in the compiled binaries makes it difficult to know in general what the expected object types are for private messages. You will have to rely on forum discussions and trial-and-error to figure it out. Armed with this knowledge of the method declaration, we can now write a fake category declaration to convince the compiler that this method really does exist: @interface UIApplication (FakePrivateMethods) - (void) setApplicationBadge:(NSString*)text; @end

The name of the category doesn’t matter, because you won’t be providing an implementation; as long as the name doesn’t conflict with any existing category name on that class, you’ll be fine. (You will seldom find real categories with the name FakePrivateMethods, so that should be a good choice.) And best of all, the compiler will never complain about the fact that your fake category has no implementation. So now the compiler is convinced that this method exists, and you can call it freely anywhere that it’s declared. (I suggest creating a header file for your project called PrivateMethods.h, and putting all your fake categories there so that you can #import your declarations easily in multiple files.) At runtime, when you invoke the call, the Objective-C runtime will look for an implementation that matches that selector—and it will find the implementation that already existed in the framework. Success! ——George Dean IV

chapter 11 - Access Private APIs

345

Run Linux on Your iPhone Because some people just can’t help themselves Even though most of Apple’s proprietary iPhone OS has been cracked open like an egg, there is still a strong desire in some circles to install a truly open OS on the iPhone. Enter the most popular open source kernel: Linux. It boots! But that’s about all it does right now (Figure 11-49).

Figure 11-49. openiboot

This effort has a long way to go—their own progress chart (Figure 11-50), at www.iphonelinux.org, tells the story.

Figure 11-50. iPhoneLinux.org’s progress chart

The “Make It Useable” work item is color-coded red, meaning that it’s unfinished and not yet even being actively pursued. Still, the work continues. It’s a huge challenge, because of all the hardware drivers that have to be reverse-engineered. It’s more of a proof-of-concept at this point (Figure 11-51).

346

iphone hacks

HACK # 11.15

Run Linux on Your iPhone, cont’d

Figure 11-51. Image courtesy of Salvatore Iovene, www.geekherocomic.com

Maybe you’re wondering why anyone would bother, when there’s already a generally wellliked OS on the device. It’s like Mount Everest. Somebody has to do it—because it’s there. ——George Dean IV

chapter 11 - access chapter private apis 11 -

347

12

Hardware Hacks In the future, everyone will have a personal computer with all their information on it, and they will carry it around in their pocket. That future is now, and the computer is called the iPhone. But just because all our data is on a little pocket computer doesn’t mean we can access it the way we want to. To a large degree, we’re relying on cloud connectivity—our data pushes up from our PCs or Macs, to the cloud, and down to our iPhone. We’re untethered, but still dependent upon the network and our home PC. What we need is a way to finish the transformation, and make it so we don’t even need a personal computer—make it so that everything is in the phone. That’s what the future holds—if you look. This chapter will go over the dozens of things you can do to enhance your iPhone-centric lifestyle with hardware and accessories. You’ll learn how to view your iPhone media on your home TV, in the car, and in the hotel room when you’re traveling, and how to keep it charged as you go. If you’re handy with a screwdriver and a spudger, this chapter will show you how to disassemble and reassemble all the iPhones and iPod touches. And if you’re the circuit builder type, you’ll learn methods for connecting and controlling almost any device—serial or otherwise—to your iPhone, without having to jailbreak it!

Hack 12.01:

Adapt Existing Headphones to Work with the Original iPhone

You can easily adapt hard-to-fit 3.5 mm plugs into a firstgeneration iPhone. If you’re using an original iPhone, you know that the headphone jack is recessed, making it harder to plug devices into it. There are countless adapters and splitters you can purchase to let you pull this recessed jack out and plug normal devices into it. Figure 12-1 shows an example from Boxwave (www.boxwave.com/products/iphoneheadsetadapter/index.htm).

348

iphone hacks

HACK # 12.01

Figure 12-1. Boxwave iPhone 3G headphone adapters (picture courtesy of Boxwave.com)

Hacking the Wire To make other 3.5 mm plugs work, you simply need to hack away at the plastic sleeve to make enough room around them so they’ll fit in the hole. The technical problem that normally prevents most headphones from connecting is the plastic sheath at the base of the plug. The girth of this plastic piece is too wide to fit in the narrow recess surrounding the iPhone’s headset port. If you compare the plug of the iPhone headset to that of a standard set of headphones, you’ll notice the difference in thickness. To get the 3.5 mm plug of almost any standard pair of headphones to fit in your iPhone, you will need to shave off about 5 mm of the plastic sheath, as shown in Figure 12-2.

Figure 12-2. Hacked old iPhone headphones 5 mm

After shaving offPlastic originally 5 mm of plastic went out to here

Some headphones and cables have a large metal disk at the base of the plug, making it impossible to shave down without a metal grinder. Check for this before you start gouging the plastic cover. Although the alteration to your headphones is cosmetically irreversible, none of their functionality will be compromised. They still will work perfectly with any other device.

chapter 12 - Adapt Existing Headphones to Work with the Original iPhone

349

Hack 12.02:

Make the Original iPhone Dock Work for the iPhone 3G

Even though the iPhone 3G didn’t come with a dock, you can shave an old dock to work. You can modify the iPhone dock that comes with the original iPhone to be compatible with and fit the iPhone 3G. Here are the tools you’ll need:

1. 2. 3. 4.

Clear packing tape Sharp tool (I used a cheap utility knife) Small flathead screwdriver 100-grit aluminum oxide sandpaper (found in the paint aisle of any home improvement store for about $2.50)

Step 1 Cover the male (inside cradle) and female (on back of dock, along with the line out plug) dock connectors with tape to insulate them. You don’t want plastic shavings to ruin the connectors! Step 2 Start carving out the inner sides and back of the dock with the sharp tool of your choice. Cover your desk with something to make it easy to dispose of all the shavings. Carve for 5 minutes at a time, and then take the tape off the male dock connector to test out your progress as you go. You can use the small flathead screwdriver to help take the tape off of the male dock connector. Don’t forget to recover the connector with tape after each test. Don’t worry about making your carvings even or smooth. (That will be addressed in the final step.) Step 3 Once you think the iPhone sits nicely, test out the connection to make sure that your iPhone 3G syncs (taking the tape off of the connectors, obviously). Step 4 Reapply the tape to the connectors. Step 5 Sand down your carvings with the 100-grit aluminum oxide sandpaper. This is pretty messy, so you may want to do this part over a trash can while you’re wearing safety glasses. Overall, this entire process should take around an hour, including the time going to the hardware store to get the sandpaper—depending on how far away your hardware store is! Figures 12-3 and 12-4 show the results.

350

iphone hacks

HACK # 12.03 Figure 12-3. Original iPhone dock modified to accept iPhone 3G

Figure 12-4. iPhone 3G resting in modified iPhone dock

Hopefully, this hack will help save the money it would require to purchase the new 3G dock! ——Matthew Drengler

Hack 12.03:

Make Noise-Cancelling iPhone Headset

You can use existing noise-cancelling headphones with your iPhone—or, better yet, improvise with the ones you have. Sometimes the person you’re calling can hear you just fine, due to the well-designed microphone, but you just can’t hear what he or she is saying because of the noise around you (Figure 12-5). You could always use a pair of noise-cancelling headphones (Figure 12-6). If you have an original iPhone you’ll have to either modify the plug [Hack #12.01] or use an adapter.

chapter 12 - Make Noise-Cancelling iPhone Headset

351

Figure 12-5. What was that?

Figure 12-6. Bose QuietComfort headphones with an iPhone microphone adapter

There are many brands of noise-cancelling headphones on the market today. What you may not know is that over-the-ear noise-cancelling headphones work just fine over the headphones that come with your iPhone. If you own an original iPhone you’ll get the benefit of noise-cancellation, without having to buy an adapter (Figure 12-7). Figure 12-7. Noise-cancelling headphones over the iPod headphones

352

iphone hacks

HACK # 12.03 Now if you want that quiet stillness but you don’t have noise-cancelling headphones, there’s a very low-tech solution: ear protection gear from a hardware store. Any Home Depot or similar store should carry them (Figure 12-8).

Figure 12-8. Ear protection

Figure 12-9 shows a happy improviser understanding the other party, now that the distracting noises have been eliminated.

Figure 12-9. Improvised noise-cancelling headphones

——Damien & Matthew Stolarz

chapter 12 - Make Noise-Cancelling iPhone Headset

353

Hack 12.04:

Use the iPhone Camera for Close-Ups

With the right lens, you can take sharp close-ups with your iPhone’s camera. The iPhone camera has a modest yet respectable 2 megapixel resolution, but no integrated optical zoom capabilities. It was designed for point-and-click simplicity with very little variability left to the user. As there is no user-adjustable focus, the iPhone is set at “infinite” focus, which is fine for just about anything but close-ups. Close-ups are important for a number of reasons. If you’re trying to use your iPhone to document fine details of objects that you’re working on, or scan bar codes on products to look up prices, or even to take a picture of a business card you’ve been given, you need close-up focus (often called macro mode), which the iPhone lacks. Fortunately, a number of pre-existing, new, and improvised products and tools can help alleviate this problem.

Physically Adjust the Focus of the iPhone’s Camera If you want to use your iPhone only for close-up shots, and you don’t want anything attached to your iPhone, then you can try the surgical approach: open the iPhone and change the focus. The process entails opening the phone up, isolating the camera unit, and using pliers to break the glue seal that holds it in the “infinite focus” position. You can see more details on this process as performed by Daniel Forsythe at www.eastrain.com/?p=73. You can see examples of a photo taken with this adjustment at www.flickr.com/photos/defor/sets/72157606981066775. You can learn about disassembling your iPhone in [Hack #12.10] and [Hack #12.11].

Use Camera Viewfinders Patrick Ng, a photography and gadget enthusiast used the viewfinders from Lomo cameras (available from http://shop.lomography.com) to achieve some interesting artistic effects, which he details here: I use my iPhone camera mostly for shooting objects, but I’m not going to limit my options by modifying the built-in camera as described earlier. So I decided to try using viewfinders from Lomo cameras to see what I could achieve (Figure 12-10). Figure 12-10. Lomolized iPhone camera

354

iphone hacks

HACK # 12.04 All these Lomo camera lenses have add-on viewfinders and they have great effects on the iPhone! The Diana+ wide-angle lens, LCA+ wide-angle lens, and Fisheye each create unique imagery. I carry my Diana+ wide-angle viewfinder with me all the time because I love the way I can hold it in front of my iPhone using its viewfinder holder (Figure 12-11). I can play with numerous analog effects: adding a prism in front, creating a pack film effect by painting/printing on a transparent film as filter, etc. I’m trying to find an easier way to put dozens of filters in front of the viewfinder so that I will be carrying only one gadget for a lot of different effects (Figures 12-12 and 12-13). By the way, the Diana+ viewfinder holder can actually hold any of these viewfinders.

Figure 12-11. Lomolized iPhone holding position

Figure 12-12. Lomolized iPhone Camera—Diana+ wide-angle viewfinder and painted film

Figure 12-13. Lomolized fisheye shots

chapter 12 - Use the iPhone Camera for Close-Ups

355

In addition to “Lomolizing” your iPhone, using the Diana+ wide-angle viewfinder as an iPhone addon lens not only improves close-up quality, but also even allows you to create a double-exposure effect (Figure 12-14) as well as a kaleidoscope effect.

Figure 12-14. Double-exposure effect

If you look at the Diana+ viewfinder closely, you’ll see a top window collecting light for the cross-hair seen through the viewfinder. By prying open the top window, you will be able to remove the crosshair film and replace it with anything you like, such as some negative/positive film or a painted transparent film, thereby creating an overlay or double-exposure effect when the viewfinder is used to take shots. Mobile Phone lenses There are several close-up lenses designed specifically for mobile phones—and the iPhone specifically. The eyeMobile KC-1 (Figure 12-15) is available at http://store.mouse. ne.jp/?language=en. The lens attaches to the iPhone with a wide circle clip. You can carry it on a keychain when you aren’t taking close-ups.

Figure 12-15. eyeMobile KC-1 close-up lens

For the second-generation iPhone, Griffin has created the Clarifi case, which includes an integrated, switchable overlay lens (Figure 12-16). See www.griffintechnology.com/products/clarifi.

356

iphone hacks

HACK # 12.04 Figure 12-16. Griffin Technology’s Clarifi 3G Case

Improvise a lens If you don’t want to break open your phone or buy viewfinders, you can get by with a simple magnifying glass. Figure 12-17 shows some of what Richard Dodd achieved with the magnifying glass from a Swiss Army knife. You can see the rest of the set at www.flickr.com/photos/cellodick/ sets/72157601804979593/detail.

Figure 12-17. Close-ups using an iPhone and a small magnifying glass (pictures courtesy of Richard Dodd)

——Damien Stolarz & Patrick Ng

chapter 12 - Use the iPhone Camera for Close-Ups

357

Hack 12.05:

Watch Your iPhone or iPod touch on a TV

Don’t pay $11.99 to rent a bad movie when you have your own personal entertainment already on your iPhone. If you’ve spent any time on the road, you know that hotels charge unconscionable fees for simple little things like ordering a movie. But you know that if you crack open your laptop, you’re likely to get distracted, not watch the movie, and thus tragically fail to chill out. And even if you get the movie started, the excessive lap heat generated by the whole laptop-in-bed thing might limit your reproductive life (depending on your gender, of course). So you try to catch up on that science fiction series on your iPhone screen, but your neck gets sore, your hands don’t want to hold anything, and you’re just not getting the relaxing audiovisual experience you needed. Luckily, there is a solution.

dd

Before you try this hack, check the television for audio (red and white) and video (yellow for NTSC or red/green/blue for component video) inputs. If the TV has those, then you can plug your iPhone directly into the TV (with the appropriate iPhone video cable or dock). See “Swanky Hotels,” at the end of this hack.

RF Modulation An RF modulator, or radio frequency modulator, is a very geeky term for a simple device: it makes the yellow-red-white audio/video output wires show up on channel 3 or 4. It’s that simple. If you had an Atari, Nintendo, or other video game systems of yore, with a correspondingly antique television, you may vaguely recall a little box that screwed into the back of the television and plugged into your game console. Well, amazingly, your video source is now smaller than the little box, but you can still buy those things and “hack” into the hotel television. What you’ll need:

1. 2. 3. 4. 5.

358

iphone hacks

RF modulator (Figure 12-18) Pliers and/or hands Apple composite A/V cable (Figure 12-19) Composite extension cables, so you can keep your iPhone right next to you and use headphones to listen (optional) Spare coaxial cable (to connect the RF modulator to the TV)

HACK # 12.05 Figure 12-18. RF modulator

Figure 12-19. Apple composite AV cable

Figure 12-20 shows the coaxial jack that you might find on the back of your hotel TV. If you can’t unscrew it from the TV, try finding the other end, where it comes out of the cable box or proprietary hotel-video-rental guest-exploitation-unit. Once you’ve unscrewed one end or the other, connect the TV to the output of the RF modulator. Note how everything was before you start, so you can put everything back the way you found it when you’re done outsmarting “the man.”

chapter 12 - Watch Your iPhone or iPod touch on a TV

359

Figure 12-20. Cable input on TV

Once you’ve got this connected, you’ll be able to watch any movie or video podcast in your hotel room. And if you have an iPhone 3G or an available Wi-Fi connection, you can probably buy a movie via iTunes for the price that it would cost to rent it from the hotel!

Swanky Hotels If you’re staying in a hotel that has a high definition flat-screen, chances are that the video inputs work—and chances are that you’re not trying to go cheap on the entertainment options, anyhow. But if the content on your iPhone is all you want to watch, you can also purchase Apple’s component A/V cable, which gives you the red-green-blue RCA cables for analog HD. Of course, video is not all you can do with your TV-out connection on an iPhone. And no, we’re not talking about viewing PowerPoint presentations [Hack #4.03]. You can use almost any iPhone application on the TV—see [Hack #12.06].

Hack 12.06:

with TV-Out

Mirror or Output the iPhone Screen

ScreenSplitr and TVOut do just what they say—to great satisfaction. Apple makes lovely cables (Figure 12-21) that plug into the bottom of the iPhone and iPod touch with the ubiquitous red-white-yellow RCA connectors on the end. They let you play movies on screens larger than 3 inches, and output audio to speakers. (There’s even a component version of the adapters if you want HD output.)

360

iphone hacks

HACK # 12.06 Figure 12-21. Pretty white Apple cables

But what if you wanted to give a Steve Jobs–style demonstration of a new app you made, with your iPhone screen mirrored on the monitor behind you? The iPhone won’t do this out of the box, but with the following two applications available on Cydia [Hack #1.04] you’ll be able to mirror your iPhone screen with TV-Out.

ScreenSplitr ScreenSplitr is a workaround (available via Cydia) that, when enabled, mirrors the video output of your entire device and all its applications. It has a simple one-button operation (Figure 12-22); tap the icon to toggle video-out. This app will transmit anything on the screen over the wire to your TV, and the image will stay on the iPhone’s screen so that you can control it easily. The disadvantage is that the frame rate on the external feed is noticeably lower than normal.

Figure 12-22. ScreenSplitr’s only real interface: the icon

TVOut TVOut, also available on Cydia, lets you toggle video output for each individual application (Figure 12-23). When an application is being sent to an external monitor with TVOut, it is not shown on the iPhone itself. Because of this, it can be hard to control (you can’t see the screen, which makes tapping/touching difficult), but the advantage is that it displays at full frame rate.

chapter 12 - Mirror or Output the iPhone Screen with TV-Out

361

Figure 12-23. TVOut’s list of application toggles

The high frame rate of TVOut allows you to easily play game emulators on external displays, with the iPhone as a controller. You can see an example of this in Figure 12-24.

Figure 12-24. Playing NES on a screen with an iPhone

Hack 12.07:

Connect the iPhone to a Car

There are many ways to enhance your drive with the iPhone. For the past hundred years, almost every type of audiovisual entertainment has eventually made it into the vehicle. Sure, the phonographs tended to skip a lot, but with tapes and CDs and DVDs, it’s worked out pretty well. So it was only a matter of time before iPod integration became a standard feature in the car. And because the iPhone honors its iPod heritage, many of the solutions for earlier iPods still work for the iPhone. And those few features that don’t work are remediable.

362

iphone hacks

HACK # 12.07

Front-Seat Entertainment Connecting your iPhone or iPod touch to the vehicle is relatively easy and very satisfying. There are four basic ways to get iPhone audio to play through your car’s speakers:

1. 2. 3. 4.

Tape adapter Radio adapter Car stereo auxiliary input iPhone dock integration

The first two solutions are widely available at any big-box retailer, electronic store, RadioShack, or Apple Store: just connect them via the iPhone’s 3.5 mm headphone plug, and you’re up and running. The third, auxiliary input (if your car has it), is a fortunate development in automotive manufacturing, and simplifies the process greatly. All you need is a 3.5 mm male-to-male extender (the same cable that connects most PC speakers to the PC), and your iPhone can plug right in. The fourth option (Figure 12-25), an iPhone or iPod dock connector, is the slickest one, especially if you can get a car with it preinstalled.

Figure 12-25. iPod integration in a Lexus 400h

iPod/iPhone Integration One of the problems with iPod integration is that iPhone integration isn’t perfect. For one thing, the iPhone 3G won’t charge via many of the iPod integration systems, because they provide 12V to the FireWire pins [Hack #12.17] instead of 5V. Figures 12-26 and 12-27 show two adapters that solve this problem: one by Scosche (www.scosche.com/products/productID/1667) and the other by CableJive (http://cablejive.com/chargeconverter.html).

chapter 12 - Connect the iPhone to a Car

363

Figure 12-26. Scosche passPORT 12V to 5V charging adapter

The CableJive adapter also has a mini-USB output if you have to charge some other device (your Zune, maybe).

Figure 12-27. 12V to 5V charging adapter

Even if you’ve adapted the power, you may not have enough reach to keep your iPhone accessible. As you can see in Figure 12-26, you now have a rigid, somewhat unwieldy 4-inch protrusion from the bottom of your iPhone. And unlike a traditional iPod, whose sole purpose in life is to play music, your iPhone also wants to make phone calls, and you may need it within reach to answer or place a call, or just to see who’s calling. For this, CableJive makes a dock extender (Figure 12-28).

Figure 12-28. CableJive’s dock extender

364

iphone hacks

HACK # 12.07 [Hack #12.17] shows you a couple more adapters that you can use to charge your iPhone—and even how to build your own.

Adding iPod integration If your car didn’t come with auxiliary input or iPod integration, don’t despair: there are hundreds of aftermarket options available that might match your car. Some leading aftermarket vendors of iPhone-car integration are www.pac-audio.com, http://peripheralelectronics.com, and www.pie. net. You can go to their sites and browse lists of their applications (i.e., a kit for a specific car). One unique product worth mentioning is iSimpleSolutions iPhone integration system (Figure 1229). It works with any late model car that is satellite radio–ready (which is a lot of them) and tricks the radio into thinking the iPhone is a satellite radio. You can browse the music collection, see track and artist names, and of course charge the iPhone while it’s plugged in (www.isimplesolutions. com/CES/Gateway.asp).

Figure 12-29. iSimple Gateway iPhone car stereo integration

Controlling Your iPhone/iPod touch The name of the game in driver safety is keeping your eyes on the road, hands on the wheel. Scosche also makes a clever device for controlling your iPod (Figure 12-30), which, though in this sense unsupported by Scosche, also happens to work for the iPod touch and iPhone (www.scosche.com/products/sfID1/210/sfID2/324).

Figure 12-30. Scosche IPNRFC iPod remote control

Rear-Seat Entertainment If you’ve got kids who ride in the car with you, you probably have learned about the “electric babysitter.” Putting screens in the rear headrests of your vehicle is the humane thing to do on long drives (unless you were thoughtful enough to buy a car just for its integrated DVD player).

chapter 12 - Connect the iPhone to a Car

365

The Apple composite A/V adapter [Hack #12.05] easily plugs into the composite input of almost any in-vehicle screen (Figure 12-31), and can even drive multiple screens with a simple RCA jack splitter (Figure 12-32). Vizualogic (www.vizualogic.com) created the screens for this Dodge Caravan, and they sell screens to match the vinyl, leather, or fabric of almost any modern vehicle for a factoryintegrated look. If you don’t want to permanently install rear screens, you can get a pair that install quickly by hooking to the rear headrests at stores like Target, Wal-Mart, or Best Buy (in the United States).

Figure 12-31. Dual Video display from an iPhone

Figure 12-32. RCA splitter

Because the adapter has a USB plug as well, you can charge while playing. Automotive USB power adapters are available for $5–$10 at many electronics retailers. The one in Figure 12-33 is a doubleheaded adapter, so you can charge two devices at once.

Figure 12-33. Auto 12V power socket to USB adapter

366

iphone hacks

HACK # 12.07 If your screens in headrests come with wireless headphones, you can connect the white and red (left- and right-channel) RCA connectors to the headrest input. But if you want the sound to go through the stereo system, you may need to use an adapter (Figure 12-34) to convert the RCA back into a 3.5 mm stereo output.

Figure 12-34. RCA to 3.5 mm adapter

If your vehicle comes with a center console, you can do a clean, hidden install, where the iPhone or iPod touch is accessible to the front seat, and the power, audio, and video cables are tucked away (Figure 12-35).

Figure 12-35. Hidden away in your center console

There’s one issue that occasionally comes up that creates an annoying buzz in the sound. This is caused by signals from the car looping back through the ground connection of the device. A ground loop isolator (available from RadioShack and www.crutchfield.com), as shown in Figure 12-36, goes between the audio outputs and stereo input, and eliminates this noise.

chapter 12 - Connect the iPhone to a Car

367

Figure 12-36. Ground loop isolator

In-Vehicle Internet If you have an iPhone 3G, then you already have near-broadband speeds in areas that are served by AT&T’s 3G network. But if you have an iPod touch or an original iPhone, you may feel out of touch on the road, unable to play network games and download movies. But there’s a solution to that, too. There are several devices that can help make your vehicle into a Wi-Fi hotspot. Portable wireless routers, such as the Kyocera KR-1, turn a Verizon or Sprint EV-DO mobile broadband card into a wireless hotspot (Sprint sells a portable router for $140 as well). CradlePoint (www.cradlepoint. com) also makes portable wireless routers (Figure 12-37). You can find a full list of similar devices at www.evdoinfo.com. All of these products provide Wi-Fi to any device you’ve got, so if you’re trying to make sure that you’re almost always online, these are an essential addition to your arsenal of gadgets.

Figure 12-37. CradlePoint portable wireless router

368

iphone hacks

Hack 12.08:

HACK # 12.08

Use Your iPhone with Gloves On

You can keep your hands warm and still use your iPhone. The iPhone has a capacitive touch screen. That means it’s registering the presence of a conductive object, such as your finger, and not the pressure of your touch as you might expect. If you’re curious, get a piece of carrot and try to use your phone with that. You will find that it works just as well as your finger. When you’re wearing mittens or gloves in colder climates, it’s uncomfortable and inconvenient to keep taking them off and on in order to operate a touch device like the iPod. While some gloves have fingertip caps that you can open, it is at times too cold to comfortably do this. What you need is a way to make your fingers work right through the glove. There are several approaches to making the fingertips of your gloves conductive: • • • •

Put conductive glue on the fingertips Sew conductive thread into the fingertips Attach rivets Buy ready-made conductive gloves

DIY Conductive Glue To make conductive glue, grind mechanical pencil leads (Figure 12-38) into a fine powder and mix the graphite powder with a minimal amount of Elmer’s rubber cement (Figure 12-39). Glue should be added one drop at a time while stirring, until you get a paste-like consistency. At first you just get gooey balls of graphite, but as soon as you’ve added enough glue, it turns into a black sludge. Then put the glove on your hand, and dip your thumb and index finger in the bowl. You have to be moderately quick, because it will dry quickly. Also, it’s pretty messy. You will get graphite on your hands, and probably any surface you are working on. It goes without saying that although graphite isn’t poisonous like lead, you probably don’t want to use your nice cooking pestle and mortar set to do the grinding. Surprisingly, this actually works, and it works well. It gives a natural feeling, and good control. You don’t have to layer it on too thickly for it to work; you might just try a dot of glue, or a thin coating. The drawback of this solution is that sometimes you may leave graphite smudges on things, but these can be wiped off.

Figure 12-38. Mechanical pencil lead, ready for grinding with a pestle

chapter 12 - Use Your iPhone with Gloves On

369

Figure 12-39. Rubber cement mixed with powdered pencil graphite

Rubber cement costs about $5 and you’ll probably spend another $5–$10 for the pencil lead. So at $15, the glue option is the cheapest, easiest, and quickest to apply, and gives the best control over the phone. The price of pencil leads is usually the same regardless of the thickness of lead, so you get slightly more for your money if you buy the thickest pencil lead you can.

Conductive Thread Conductive thread (Figure 12-40) works well, and can be made to look nice, depending on your sewing skill levels. Both finger and thumb work fine, but the stitching on the index finger (Figure 12-41) gives more control than the thumb. Although more thread works better, experimentation showed that a minimal amount of thread was still functional (Figure 12-42).

Figure 12-40. Conductive thread

Conductive thread can be purchased from SparkFun Electronics (www.sparkfun.com, part number DEV-08549). In this hack, 4-ply thread was used, but 2-ply would probably also work well, and might be more attractive. The price is currently about $20 a spool plus shipping, but one spool could easily do multiple pairs of gloves and be used for other projects.

370

iphone hacks

HACK # 12.08 Figure 12-41. Conductive thread stitching on the index finger

Figure 12-42. It works just fine!

Premade Solutions An inexpensive, already conductive solution for the problem of cold hands and iPhones is made by DOTS (Figure 12-43): the iPhone Glove.

Figure 12-43. DOTS iPhone Gloves

——Christopher Kurpinski

chapter 12 - Use Your iPhone with Gloves On

371

Hack 12.09:

Peek Inside Your Device

Whether you’re replacing the battery or replacing the screen, this hack will introduce you to the delicate steps of iPhone surgery. There is a wonderfully macabre portion of the iPhone and iPod touch community that can’t help but recklessly disassemble and document each new model as soon as they come out. They revel in unveiling the inner workings and most secret physical components of each soap-bar-like device. This process is often very well documented and of great help to anyone who wishes to modify, repair, or simply torture their device. This hack will focus on modifications and repair, with images helpfully provided by our disassembler friends over at iFixit (www.ifixit.com), which is also a great source for any of the parts you might need in the repair of your device.

dd

Most disassembly instructions for devices will drop a bomb on you right at the end of the instructions that “reassembly is the opposite of disassembly” or “reverse these steps to reassemble.” At that point, you may suddenly realize that you haven’t exactly been keeping track of which screw goes where, or even taking care not to lose the screws. Here we’ll warn you ahead of time. So find some shotglasses or plastic food storage containers, such as ice cube trays, to save the screws (Figure 12-44), and pay attention to the steps, thinking about them backward as well as forward so that reassembly will be as easy as possible. If you keep a camera handy to take photos of your work at each critical step, it will make it way easier to backtrack.

Figure 12-44. Screws saved in a shotglass

Tools Spudgers are the most generic-seeming yet most crucial tool for disassembly of tightly constructed devices such as the iPhone (Figure 12-45). They’re sticks of plastic or metal with different tips. Often they have wedges, hooks, or points. Devices like the iPhone aren’t like toy guns, in that they don’t have lots of loose plastic that can simply be screwed together. They use systems of internal clips and wedging, the disassembly of which requires specific spudgers if you want it done right—and without serrated butter-knife marks on your casing. The steps in the this hack will reference specific kinds of spudgers, as well as a special tool called the iPod Opening Tool. Next is a rundown on the specific spudgers and other tools.

372

iphone hacks

HACK # 12.09 Figure 12-45. Using a metal spudger to remove the screen from an iPod touch

The simple spudger (Figure 12-46) has a wedge with a hook on one end, and a pencil-like point on the other end. It’s made of tough and antistatic plastic. It is used in prying, lifting up connectors, and at one point in this disassembly, scraping away glue.

Figure 12-46. The spudger

The heavy-duty spudger (Figure 12-47) has a thicker wedge and thicker point. It does the “heavy lifting” as it were. It is plastic, like the regular spudger.

Figure 12-47. The heavy-duty spudger

The metal spudger (Figure 12-48) is even sturdier, because it is metal. It’s used in the prying of certain edges as well as in the removal of the original iPhone’s antenna cover.

Figure 12-48. The metal spudger

chapter 12 - Peek Inside Your Device

373

The iPod Opening Tools (Figure 12-49) are specially made for prying up the edges of iPods and iPhones without damaging them. They are made of a lighter material than that of the iPod, and thus are prone to damage if not used properly. Too many failures could result in them being unusable, in which case a thin metal blade or guitar pick would work as a replacement.

Figure 12-49. The iPod opening tools

The #00 Phillips screwdriver (Figure 12-50) is a very small screwdriver, used for the kinds of tiny screws that you’ll find in small precision devices like iPhones.

Figure 12-50. The Phillips #00 screwdriver

To whet your appetite for disassembly fun, here are four grand reveals of iPhone and iPod touch insides. Figure 12-51 shows a disassembled original model iPhone—the same model that is pictured partially nude on the cover of this book as a teaser.

Figure 12-51. You can tell it’s the original iPhone from the black plastic antenna cover portion.

374

iphone hacks

HACK # 12.09 Figure 12-52 shows a dismembered iPhone 3G, with all the fixins.

Figure 12-52. The iPhone 3G, which comes with all that you see here

Figure 12-53 shows a filleted original iPod touch. It looks simpler than the iPhone, because it is: no SIM card, camera, or microphone.

Figure 12-53. The original iPod touch

Figure 12-54 shows a splayed iPod touch 2G. It’s like the original version, but rounder.

Figure 12-54. The opened-up original iPod touch

chapter 12 - Peek Inside Your Device

375

The following four hacks will give you disassembly instructions for both generations of iPhone and iPod touch. By the time you’re done reading, you’ll feel like you could disassemble anything.

Hack 12.10:

Disassemble and Reassemble Your Original iPhone

Master the skill of disassembling and reassembling your iPhone. Taking apart the first-generation iPhone is quite different from taking apart the iPhone 3G.

The advanced stages of this hack require soldering experience. If you don’t have

experience soldering, check out the Learn to Solder Bundle from MAKE, available at www.makershed.com/ProductDetails.asp?ProductCode=MSBUN1.

The first thing you’ll want to do before you start taking apart your phone is to remove the SIM card tray by inserting a paper clip into the hole on top of the iPhone and sliding the tray out (Figure 12-55). If you don’t do this, you’ll likely bend or break your SIM card tray at some point in disassembly.

For tips on reassembling the device, as well as an overview of the tools used here, see [Hack #12.09]. Figure 12-55. Popping out the SIM card tray

The next part necessary in any iPhone disassembly is removing the black plastic antenna cover (Figure 12-56). It has four tabs that you need to pop open with a metal spudger and an iPod opening tool. First, release the tabs near the dock connector by sliding a metal spudger in-between the dock connector and the antenna cover (Figure 12-57). Make sure that you’re actually sticking it between those two pieces and not simply sticking it in the dock connector. Next, insert the wedge of the iPod tool between the front metal bezel and the antenna cover (Figure 12-58). The wedge should be facing the antenna cover. Slide the iPod tool up and around the corner to unhook the side tabs. Do this once for each side. Next, grab the panel by the sides, lift it away, and slide it off the iPhone (Figure 12-59). This might take some force. If it doesn’t seem to be coming off, make sure you’re lifting it out from the iPhone before you slide it off down the bottom.

376

iphone hacks

HACK # 12.10 Figure 12-56. The antenna cover

Figure 12-57. Putting a metal spudger in-between the dock connector and antenna panel

Figure 12-58. Sliding an iPod tool between the metal frame and antenna panel

chapter 12 - Disassemble and Reassemble Your Original iPhone

377

Figure 12-59. Removing the antenna panel

Next, the metal rear panel is the object of our deconstruction. You’ll want to unscrew the three Phillips #00 screws that attach the panel to the rest of the phone (Figure 12-60). Make sure to note where these were (check the photograph for help) and tuck them away safely. Now, this panel is rather hard to remove, so don’t get discouraged or angry at it, or you may damage it more than you intended to. Now you’ll need to do more prying. Start with the side that doesn’t have the volume buttons, as whichever side you tackle first is going to be the hardest to get, and then you won’t risk damaging those buttons. Insert the point of a heavy-duty spudger into the gap between the rear panel and the area around where you removed the screw (Figure 12-61). Gently pry the frame upwards until you can insert an iPod tool in the gap between the bezel and rear panel. Slide the iPod tool along the side of the case and pop the four tabs open (Figure 12-62). Make sure during the remaining steps that you don’t squeeze the case and repop the tabs back into place. Now repeat the same pry-and-pry procedure on the button side (Figure 12-63), which only has 3 tabs. Now you can lift off the rear panel. But don’t yank it off, as you still need to use a spudger to disconnect the headphone jack cable from the logic board (Figure 12-64).

Figure 12-60. Unscrew three Phillips #00 screws

378

iphone hacks

HACK # 12.10 Figure 12-61. Insert heavy-duty spudger

Figure 12-62. Slide iPod tool along case

Figure 12-63. Slide iPod tool along other side of case

chapter 12 - Disassemble and Reassemble Your Original iPhone

379

Figure 12-64. Disconnect the headphone jack cable from the logic board

It’s Open! Now your iPhone is opened up, and you can access nearly everything from this point. The rest of this section will cover removing the battery, a common maintenance procedure. More removal instructions can be found by poking around with spudgers and screwdrivers yourself, or through the guides available on www.ifixit.com.

Removing the Battery Use the tip of a spudger to remove the cloudy white glue covering the battery contacts, as shown in Figure 12-65.

Figure 12-65. Remove glue from contacts

Working from the edge opposite the battery connectors, insert a spudger between the battery and the plastic frame and pry up (Figure 12-66). The battery is attached to the casing with an adhesive, but should slowly come free.

380

iphone hacks

HACK # 12.10 Figure 12-66. Pry up battery

We’re now ready to begin the soldering process. You’ll need a soldering iron, solder, and desoldering wick. You should be able to find these items at a RadioShack, if you don’t already have them. Clean the soldering iron by melting a small amount of solder directly onto the soldering iron’s tip (as shown in Figure 12-67) and then wiping the tip of the soldering iron on a damp sponge.

Figure 12-67. Cleaning soldering iron tip with solder

Now, you need to disconnect the battery:

1. 2. 3.

Place the desoldering wick on top of the solder ball as shown in Figure 12-68. Place the soldering iron on top of wick above the solder ball. Hold the soldering iron in place until the solder melts into the wick.

Repeat this procedure on the remaining two connectors. Lift the old battery out of the iPhone. Be sure that all the solder has been removed before pulling the wires away from the board. The wires should come free with little to no resistance.

chapter 12 - Disassemble and Reassemble Your Original iPhone

381

Figure 12-68. Desoldering the battery from the board

Clean the exposed surface of the board with a soft lint-free cloth or sponge and a small amount of rubbing alcohol.

Replacing the Battery Melt a small solder bead directly onto the metal connector on the board by placing the soldering iron onto the metal connector and then pressing solder against the tip and the board. Once a small amount of solder has melted onto the board, lift the solder away first and then the soldering iron. See Figure 12-69.

Figure 12-69. Prepare soldering area

The solder bead should look like a small dome or hemisphere (Figure 12-70). If it is flat or jagged, simply place the soldering iron back on the solder to remelt it and then pull the soldering iron away. It may require a little more solder if this does not work.

382

iphone hacks

HACK # 12.10 Figure 12-70. Good solder beads

Place the wire from the new battery onto the new solder bead. Press the tip of the soldering iron onto the solder bead until it melts, as shown in Figure 12-71. Slide the wire lead into the liquid solder until it is in the center of the bead, then remove the soldering iron. Continue with the other two connections the same way, taking special care not to solder two of the connectors together. That would make for major iPhone sadness.

Figure 12-71. Soldering a battery wire

If you’ve successfully followed all these steps, congratulations! You’ve taken apart the most complex of the four devices covered in this chapter. The more Apple has redesigned these soap bars, the better the insides have become to dig around in. ——iFixit.com & Adam Stolarz

chapter 12 - Disassemble and Reassemble Your Original iPhone

383

Hack 12.11:

Disassemble and Reassemble Your iPhone 3G

Master the skill of disassembling and reassembling your iPhone. The iPhone 3G is quite an upgrade from the original iPhone. The case is made of fewer parts, and all in all, the device is easier to deconstruct. Apple has even included numbered stickers to indicate what order to detach various cables. To get started, remove the two Phillips #00 screws from the dock-connector end of the iPhone, as shown in Figure 12-72.

For tips on reassembling the device, as well as an overview of the tools used here, see [Hack #12.09]. Figure 12-72. Remove the two Phillips #00 screws from the dock connector

There is a fragile rubber gasket between the silver front bezel and black display assembly. Keep your tool as close to the silver front bezel as possible to prevent damaging the gasket. A metal spudger is recommended for this task (Figure 12-73), but an X-Acto knife should also work—just be careful not to slip. Insert a metal spudger into the seam between the silver front bezel and the black display assembly on the edge closest to the home button. Gently pry the display assembly up from its bezel.

Figure 12-73. Opening the bezel with a metal spudger

384

iphone hacks

HACK # 12.11 If necessary, insert the metal spudger in the same manner on the side of the iPhone and continue to pry up gently, as shown in Figure 12-74. Stop using the metal spudger once the display assembly is up enough that you can lift it up with your fingers.

Figure 12-74. Going along the side

The display assembly is still connected to the iPhone by several cables, so don’t try to remove it entirely just yet. Lift the free edge of the display assembly up until it is at an angle of approximately 45 degrees, as shown in Figure 12-75.

Figure 12-75. Lifting the display

Continue to hold the display assembly with one hand, and use your other hand and a spudger to disconnect the black ribbon cable labeled “1” inside the iPhone, as shown in Figure 12-76.

chapter 12 - Disassemble and Reassemble Your iPhone 3G

385

Figure 12-76. Detaching cable 1

Lift the display assembly up until it is roughly vertical. This will allow you easier access for disconnecting the remaining cables. Use a spudger to disconnect the black ribbon cable labeled “2” inside the iPhone, as shown in Figure 12-77.

Figure 12-77. Detaching cable 2

Use a spudger to flip up the white plastic tab holding the third ribbon cable in place, as in Figure 12-78. The white tab will rotate up 90 degrees, releasing the ribbon cable. Slide the black ribbon cable out of its connector, and remove the display assembly from the iPhone.

386

iphone hacks

HACK # 12.11 Figure 12-78. Detaching cable 3

Insert your SIM eject tool or a paper clip into the hole next to the headphone jack as shown in Figure 12-79. Press down on the tool until the SIM card tray pops out. Grasp the SIM card tray and slide it out of the iPhone.

Figure 12-79. Removing the SIM tray

Use a spudger to disconnect the ribbon cable that is labeled “4” inside the iPhone (Figure 12-80).

Figure 12-80. Detaching cable 4

chapter 12 - Disassemble and Reassemble Your iPhone 3G

387

Use a spudger to disconnect the ribbon cable that is labeled “5” inside the iPhone, as shown in Figure 12-81.

Figure 12-81. Detaching cable 5

Use a spudger to disconnect the ribbon cable labeled “6” (Figure 12-82).

Figure 12-82. Detaching cable 6

Carefully peel up the small sticker labeled “Do not remove.” Isn’t Apple nice? They tell you exactly what to do and then tell you to turn around and go home. See Figure 12-83.

Figure 12-83. Removing the sticker

388

iphone hacks

HACK # 12.11 Next, remove the following eight screws, which are circled in Figure 12-84: • • •

Five 2.3 mm Phillips #00 screws with partial threads securing the logic board to the rear panel. Two 2.3 mm Phillips #00 screws with full threads securing the logic board and camera. One 2.9 mm Phillips #00 screw from beneath the “Do not remove” sticker.

Figure 12-84. The screws

Use a spudger to gently pry the camera up and out of its housing in the rear panel, as shown in Figure 12-85. The camera cannot be removed entirely yet, because it’s connected to the bottom of the logic board.

Figure 12-85. Prying up the camera

Use a spudger to gently pry up the end of the logic board closest to the dock connector as shown in Figure 12-86. If the board won’t lift up, double check to make sure that all the screws securing the logic board have been removed.

chapter 12 - Disassemble and Reassemble Your iPhone 3G

389

Figure 12-86. Spudging the logic board

Slide the logic board toward the dock connector and out of the iPhone (Figure 12-87).

Figure 12-87. Sliding it off

At this point, you are within a few steps of taking out anything in the phone. Whatever you can identify should be a few screws away from being uninstalled.

Replacing the Battery For those replacing their battery, here’s the best way to remove it. The battery is attached with an adhesive strip around the perimeter of the battery. Use a spudger (Figure 12-88) to pry the battery up from the rear panel (to prevent the battery from bending during the removal process, we recommend against using just the plastic pull-tab). Honestly, it is that easy. As you can see, it is not soldered on like the early iPhones [Hack #12.10].

390

iphone hacks

HACK # 12.12 Figure 12-88. Prying the battery

Now your phone is open, as shown in Figure 12-89, and you can mess with it as you see fit. You shouldn’t have any problems from here on out, particularly if you remember that the labeled wires should be reassembled in reverse order: 6-5-4-3-2-1.

Figure 12-89. The nonwire battery connector

——iFixit.com & Adam Stolarz

Hack 12.12:

Disassemble and Reassemble Your Original iPod touch

Master the skill of disassembling and reassembling your iPod touch. The iPod touch’s interior was clearly designed for ease of maintenance. Some lessons were learned in designing the iPhone that make the first-generation iPod touch simpler inside. And it helps that it doesn’t have as much stuff crammed in it as the iPhone does.

For tips on reassembling the device, as well as an overview of the tools used here, see [Hack #12.09].

chapter 12 - Disassemble and Reassemble Your Original iPod touch

391

Opening the iPod touch is similar to opening an iPhone [Hack #12.10] and [Hack #12.11]. Run a metal spudger along the sides and separate the metal tabs. The iPod touch doesn’t need a large speaker or microphone, so the battery occupies a larger portion of the internal space than the iPhone’s battery, as shown in Figure 12-90.

Figure 12-90. The cracked-open iPod touch case

There are no wires connecting the rear panel to the iPod. Apple used an elegant contact connection to make assembly and disassembly easier, as shown in Figure 12-91.

Figure 12-91. The contact connector

The large battery is soldered to the logic board, like the early-model iPhone and many of Apple’s recent iPods. You can lift it up using a simple spudger, however, as shown in Figure 12-92.

392

iphone hacks

HACK # 12.12 Figure 12-92. Lifting up the battery

The huge touchscreen lies beneath the battery. The logic board is beneath the metal shield (Figure 12-93).

Figure 12-93. Under the battery

The metal case opens easily by prying the right side, which reveals the logic board (Figure 12-94).

Figure 12-94. The logic board

chapter 12 - Disassemble and Reassemble Your Original iPod touch

393

Nearly everything in the iPod touch lifts up easily (Figure 12-95).

Figure 12-95. Lifting out the board

You can pry the logic board up and off fairly easily with a spudger (Figure 12-96).

Figure 12-96. Prying the logic board

The display attachment is completely different from the iPhone’s. The display is attached to the front of the iPod by 16 Phillips #00 screws. On the iPhone, the display and front bezel are fused together with very strong adhesive, which makes it impossible to separate the display from the glass. But the iPod’s design is better for repairs, as removing the display is very doable. The LCD just comes right out after you remove the screws, as shown in Figure 12-97.

394

iphone hacks

HACK # 12.13 Figure 12-97. Removing the plate

As you can see in Figure 12-98, compared to the early-model iPhone, the first-generation iPod touch is a dream to disassemble. Self-repair and part replacement is relatively easy compared to other models.

Figure 12-98. Detached bezel and screen

——iFixit.com & Adam Stolarz

Hack 12.13:

Disassemble and Reassemble Your SecondGeneration iPod touch

Take apart the easiest iDevice yet. As with the first generation of the iPod touch [Hack #12.12], the second-generation iPod touch benefits from a similar ease of disassembly. The second-generation iPod touch does not have a two-piece shell like the first generation. Instead, you start by prying up the glass screen cover itself. In Figure 12-99, a metal spudger is shown. Of course, be careful not to damage the edge of the glass or the case.

chapter 12 - Disassemble and Reassemble Your Second-Generation iPod touch

395

Figure 12-99. Prying the display

There are no screws securing the LCD (Figure 12-100). Instead, it’s held in place with a little doublesided tape.

Figure 12-100. Screen without covering bezel

Lifting it up reveals a metal plate hiding the goods (Figure 12-101), but that’s nothing a #00 screwdriver won’t solve.

Figure 12-101. Lifting off the screen

396

iphone hacks

HACK # 12.13 The battery is held to the plate with two strips of light adhesive, but peels off easily, as shown in Figure 12-102.

Figure 12-102. Under the metal

Disconnect the display data cable with some simple spudging as demonstrated in Figure 12-103. Note the residue from the glue holding the battery to the metal backing.

Figure 12-103. Prying off the battery connector

The battery and all the remaining parts can be lifted out easily now (Figure 12-104).

chapter 12 - Disassemble and Reassemble Your Second-Generation iPod touch

397

Figure 12-104. The remaining pieces

Simplicity of design, with little guesswork and a small handful of screws to remove means that you can easily replace anything in the second-generation iPod touch (Figure 12-105).

Figure 12-105. The touch, splayed

——iFixit.com & Adam Stolarz

Hack 12.14:

Learn the Pinouts of the iPhone and iPod touch

To connect hardware to your iPhone, you need to know its interfaces. The iPod created a whole aftermarket and third-party industry around its dock connector standard. This standard has made its way into countless speakers, charging kits, and automotive integration systems. In addition to the dock connector, though, Apple has continually experimented with various interfaces on the top of the device. The early iPods had a wired remote control connector on the top, with which you could play, fast forward, and rewind while the iPod was in your pocket. The latest family of devices (the iPhone and iPod touch) have continued this experimentation, and have added a 4-wire or “4-pole” connector for microphones and headphones.

398

iphone hacks

HACK # 12.14 Because many computer wires and plugs have traditionally involved many pins plugging into some sort of receptacle, the term for a chart showing what wire goes to which pin is called a pinout. In order to hack new devices into communication with the iPhone, we need to know the pinouts—the purpose of each wire or physical electrical contact—and thus what we can and cannot connect to it.

The Headphone Connector Pinouts The iPhone headphone system is pretty clever. Most audio-type jack plugs (male connectors) have a convention for naming the contacts called the “tip-ring-sleeve” (TRS), as shown in Figure 12-106. In most headphones, the three contacts are (from the tip to the sleeve) left-right-ground. The ground contact is twice as long as the right channel, and the jacks (female sockets) that receive them have three poles, or contacts. Many jacks have a feature that allows the computer or device to detect when something is plugged in or not.

Figure 12-106. Tip-ring-sleeve conventional 3.5 mm headphone jack. The iPhone jack is slightly different.

In the iPhone headphone, there are two rings (TRRS). The very tip of the iPhone headphone connectors is the left audio channel, and the ring after this is the right audio signal. The next ring is the conventional “ground” or return wire, and those three pins alone constitute the listening part of the headphones. In addition, there is a fourth contact, the sleeve, which is connected to the iPhone microphone (Figure 12-107).

Figure 12-107. The iPhone headphone jack plug pinout

chapter 12 - Learn the Pinouts of the iPhone and iPod touch

399

The microphone has a resistance of about 1K (1 kilo-ohm), which is used by the iPhone to detect whether a microphone is plugged in. If conventional headphones are plugged in, you can see that the sleeve would bridge both the microphone and ground pins. Thus, the iPhone senses zero ohms, indicating that only headphones are connected. If it senses 1K, it means that microphone is present as well. You can see an opened-up 4-pole connector in Figure 12-108.

Figure 12-108. Freshly soldered iPhone 4-pole plug

Ring (Ground/Common) Ring (Right)

Sleeve (Microphone)

Tip (Left)

Because of this ability to sense the resistance of the ground-mic connection, the iPhone headphones also do a couple of additional clever things. The iPhone microphone doubles as a switch (Figure 12-109) that can play and pause music, and answer or hang up a call. If you “double click” (squeeze two times fast) during music playback, the iPhone or second-generation iPod touch will skip to the next song. Monster makes an adapter that adds a microphone and switch to existing headphones, which you can see cracked open in Figure 12-110.

Figure 12-109. The iPhone microphone-switch

400

iphone hacks

HACK # 12.14 Figure 12-110. Inside the Monster adapter

Using the Headphone Jack Because we know how the iPhone microphone circuit works, we can now begin to attach our own devices. Here’s some things we can build:

1. 2. 3.

An auxiliary audio input port, so we can plug in things we want to record instead of using the microphone Hands-free car integration via a wired microphone, and a button that shorts out the mic/ ground so that we can skip songs [Hack #12.07] Nonaudio devices—such as microcontrollers, serial devices, or keyboards—that we can “listen” to by transforming their output into audio pulses [Hack #12.21] and [Hack #12.22]

Figure 12-111 shows two views of an iPhone microphone and headphone splitter. It separates out a pair of microphone and audio jacks so you can record directly from another audio device. You can see it in action with a pair of headphones and an in-vehicle microphone [Hack #12.07] in Figure 12-112.

Figure 12-111. An iPhone jack input/output splitter

chapter 12 - Learn the Pinouts of the iPhone and iPod touch

401

Figure 12-112. An iPhone jack input/output splitter in use

Finding a source for the 4-pin jack plugs, especially small ones that fit in the original iPhone recessed jack, can be challenging. You can purchase 4-pole plugs (Figure 12-113) from Maplin (www.maplin.co.uk/module.aspx?moduleno=29686). You can also scavenge them from the 4-pole cables used for camcorders from vendors like www.allelectronics.com (part number CB-218 is shown in Figure 12-114).

Figure 12-113. Maplin 4-pole plug

402

iphone hacks

HACK # 12.14 Figure 12-114. AllElectronics.com 4-pole cable part number CB-218

One of the better sources of a 4-pole adapter plug is a 4-pole Y-splitter from Radtech (part number 13757 from http://radtech.us/products/iPhoneCables.aspx), the ProCableAudio Y Cable Splitter 3.5 mm. This cable can be cut and spliced so that you can connect to the headphone port (Figure 12-115). When you cut the wires, you’ll see that they are coated in colored insulating paint. Sometimes you can just solder it and the coating will melt off, but to make sure that your connection is good, you can lightly sand this paint off (including the clear copper wire) without ripping the wire. Figure 12-116 shows a quick-and-dirty splice to heavier-duty wires that was used as we worked on [Hack #12.20].

Figure 12-115. Radtech 4-pole Y-splitter

chapter 12 - Learn the Pinouts of the iPhone and iPod touch

403

Figure 12-116. Radtech 4-pole splice

The Dock Connector Pinouts The bottom dock connector has changed over time in terms of the features that it exposes. Video out, audio in and out, 12V charging, 5V charging, FireWire and USB syncing, and various custom communication protocols have come and gone over the years. But because the iPhone remains the flagship iPod, it retains compatibility with the majority of in-market iPod dock–based hardware. Figure 12-117 shows a PodBreakout from SparkFun Electronics (www.sparkfun.com, part number DEV-08295) that is available for less than $20. Figure 12-118 shows the dock connector close up.

Figure 12-117. PodBreakout (picture from sparkfun.com)

Figure 12-118. iPod dock breakout cable: pin 1 is on the far right, pin 30 on the left (picture from sparkfun.com)

404

iphone hacks

HACK # 12.14 The pinout of the iPod dock connector has been pretty consistent since it was released; some pins get repurposed, or dropped, depending on the device and the accessory in question. A recent change between the first-generation iPhone and the iPhone 3G is that support for FireWire charging (pins 19, 20, 29, and 30) was dropped. A selected list of pins relevant to the iPhone is shown in Table 12-1. Additional pins for all models of iPod and iPhone can be found at http://pinouts.ru/PortableDevices/ipod_pinout.shtml and http://datacables.ws/iphone. Table 12-1. Interesting iPhone pins

Pin

Description

1

Video ground

2

Audio ground

3

Right channel audio out

4

Left channel audio out

8

Video out (composite, yellow plug) or Pb channel (component, blue plug)

9

Video Y channel (component, green plug)

10

Video Pr channel (component, red plug)

11

3.3V TTL (not RS232) serial ground [Hack #12.18], [Hack #12.19]

12

3.3V TTL (not RS232) serial transmit (TX)

13

3.3V TTL (not RS232) serial receive (TX)

15

Ground

16

USB ground

18

3.3 volt power output

21

Accessory indicator. Depending on the resistor connected between ground and this pin, the iPhone or iPod touch will believe that a certain device is connected, such as a car interface, dock, photo dock, and so on. For an example, see [Hack #12.19]

23

5V USB power input

24

USB data (minus connection)

27

USB data (plus connection)

dd

Although pins 8, 9, and 10 provide video output, the iPhone requires the proprietary iPhone cable [Hack #12.06] to enable the video, so you can’t just make your own dock.

Pins 11, 12, and 13 support the serial protocol that can be spoken by the iPhone to devices via the

iPod dock protocol [Hack #12.19], such as in-vehicle integration. Although it is a serial connection, it isn’t the relatively high-voltage 12V to –12V RS-232 serial connection on the back of many older computers, but rather a TTL (transistor-transistor logic) connection that goes from 0V to 3.3V to indicate ones and zeros. [Hack #12.18] shows how to adapt between 3.3V TTL and RS232 serial (as well as USB) so that you can communicate with your iPhone via a serial port.

Pin 21, the accessory connector, is part of how the iPhone detects what is connected. With various resistor settings, you can trick the iPhone into different modes, and a few of the hacks such as [Hack #12.17] and [Hack #12.19] will demonstrate this.

chapter 12 - Learn the Pinouts of the iPhone and iPod touch

405

If you’re trying to make a device to connect to the dock connector, you don’t have to buy a breakout card. In fact, with the proliferation of under-$10 iPhone connectivity gadgets, you can probably find a hackable donor dock connector from a device that you already own and don’t need, or something at your local electronics store. For instance, in [Hack #12.15] an iPhone flashlight is scavenged from a charging cable (Figure 12-119).

Figure 12-119. Old iPhone/iPod dock connector

The item you’re most likely to have already is a USB sync cable, so we’ll show how you can adapt this connector to your needs. However, if you plan to do a lot of dock connector hacking, you’ll find the PodBreakout cable from SparkFun (www.sparkfun.com; part #DEV-08295, Figure 12-125) very useful. The first task is to rewire the USB sync cable so it uses the pins you want, rather than the USB pins. Not all the pins are populated, so you’ll need to move them around for the ones you use. To do this, you will have to open up the iPhone plug using a spudger (Figure 12-120). Inside the plastic layer, you will find an additional metal layer for shielding radio frequency emissions. It should look like Figure 12-121.

Figure 12-120. Opening the connector

406

iphone hacks

HACK # 12.14 Figure 12-121. Opening an iPhone dock connector plug

You attack this layer from the side. There are two little tabs that catch at the rear. Pry them out, as shown in Figure 12-122.

Figure 12-122. Removing the iPhone plug shielding

Eventually you will remove all the metal shielding and will wind up with just the plastic plug, wires, and pins, as shown in Figure 12-123.

chapter 12 - Learn the Pinouts of the iPhone and iPod touch

407

Figure 12-123. Shields off

Leave the shielding wire soldered if you can, but if it comes off, you may find that your cable leaks some radio noise. Some places sell cables that have the wires glued into the connector. If you bought one of these, you need to purchase them from another vendor; otherwise, you will have a lot of difficulty trying to pull the pins out and reinsert them (http://allelectronics.com sells suitable connectors, part #IPD-3). Speaking of which, your next step is to use a pair of needle-nose pliers to remove the pins from their existing seats and push them back into the pins that you need to access—see Table 12-1. Pins can be pulled and reinserted with your fingers, or with needle-nose pliers, as shown in Figure 12-124.

Figure 12-124. Rearranging the pins

Once you’ve rewired and double-checked all your pins to make sure that they’re correct, you can reassemble the shielding and plastic casing.

Finding Pins It’s important in any electronics, especially with a $300 iPhone, to get the pins right. Figure 12-125 illustrates the position of the dock pins on an iPhone. Looking at Figure 12-125, pin 1 is the farthest

408

iphone hacks

HACK # 12.15 to the left. You can find pin 1 by holding your iPhone in your left hand face up. The pin closest to your left hand is pin 1. Pins 2, 3, and so on are found by counting away. Pin 30 is the farthest to the right.

Figure 12-125. Pin 1 is on the left, pin 30 is on the right

There’s a lot you can do with the dock connector. [Hack #12.15] shows you how to make a flashlight, [Hack #12.17] shows you how to build an iPhone charger, and [Hack #12.18] shows how you can turn a USB-to-dock connector iPhone cord into a serial-to-dock connector by rearranging its pins as shown in this hack. ——Damien Stolarz & Zack Gainsforth

Hack 12.15:

Make an External Camera Illuminator for Your iPhone

An iPhone-powered LED flashlight can help you take better photos. Getting your iPhone to take a good picture in a badly lit area is nearly impossible, especially as the iPhone has no built in flash. So the next best thing is to make your own external illuminator, as shown in Figure 12-126!

Figure 12-126. External Camera Illuminator

chapter 12 - Make an External Camera Illuminator for Your iPhone

409

When the iPhone’s initial specs were released by Apple, many users complained about its lack of a camera flash. Using a USB connector, four white LEDs, and a tactile switch, you can build a removable flash unit. The parts you’ll need to make a camera flash are: • •

• • •

• • •

An old iPhone/iPod dock connector [Hack #12.14] A couple of LEDs (3 mm or 5 mm super-bright white LEDs are preferable), SparkFun part COM00531 (www.sparkfun.com), RadioShack part 276-017 Insulated wire that can handle a 3.3V current such as 30-gauge wire Tactile switch (Figure 12-127), SparkFun part COM-00097, RadioShack part 275-002 10 ohm resistor (optional, but if you want to play it safe you should use it), RadioShack part 271-1301 Soldering iron and solder Dremel or similar rotary tool Super Glue

Figure 12-127. Tactile momentary switch

First, pop open the dock connector, and examine the wires connected to its pins. You should review [Hack #12.14] to familiarize yourself with the dock connector’s 30 pins and their functions. There should be a black ground wire attached to pin 29 or 30. Cut all the other wires, except the ground, as close to the pins as possible. Then cut the ground wire at a farther point so a portion of it is still hanging from the dock connector pin that it’s attached to. Now attach one end of an insulated wire to pin 18. Some dock connectors don’t have pins in all 30 positions, so you will have to slide a pin out from a different place, and insert it into position 18. To configure the remainder of the flash refer to Figure 12-128, using solder to connect each wire to its appropriate component.

410

iphone hacks

HACK # 12.15 Figure 12-128. Schematic for LED Illuminator

Dock Connector (view from back) GND (pin 30/29) +3.3v (pin 18) Optional Resistor

3.5 mm White LEDs Tact Switch

With the guts of the flash assembled, use your Dremel to drill holes in the dock connector’s shell for the LEDs to stick through. Once the LEDs are in place use some Super Glue to secure them. Next, Super Glue the tactile switch to the bottom of the dock connector shell where the wires used to be. Solder everything together. Finally, Super Glue the dock connector back together. Your custom light is complete! Plug it into your iPhone’s dock and press the tact switch on the bottom of the connector (Figure 12-129) to turn the LEDs on whenever you need some extra lighting for a picture (Figure 12-130) Figure 12-129. Light plugged into bottom of iPhone

Figure 12-130. Bright light

chapter 12 - Make an External Camera Illuminator for Your iPhone

411

Figure 12-131 shows a pair of before and after shots with the illuminator.

Figure 12-131. Before (top) and after (bottom) pictures using the iPhone flashlight

——Joe Vennix

Hack 12.16:

Control the Physical World from Your iPhone

By combining an iPhone app, Arduino, and a few transistors, you can control lights—and even an R/C car—with your iPhone. By plugging an Arduino electronics prototyping board into a network-connected computer, installing an app from the App Store, and wiring things up, you can turn your iPhone into a remote control for the physical world. This hack sounds complex, but it’s not that hard. Once you’ve gotten all the parts, it only takes about two hours to make—and the results, as shown in Figure 12-132—are worth it.

Figure 12-132. iPhone-controlled R/C Car

In this hack, you’ll start out simple: using the iPhone to make an LED blink. From there, you’ll move up to controlling a remote control (R/C) car. The system for this is pretty simple. The iPhone sends 412

iphone hacks

HACK # 12.16 data (button presses and the iPhone’s accelerometer data) over Wi-Fi to your computer, where you can perform some computations and finally send data to an Arduino board, which controls the car’s remote control (which, in turn, controls the car’s motors). First, you have to get data from your iPhone to your computer. The easiest way to do this is an application that is normally intended to be used by a DJ or musician, such as TouchOSC or OSCemote. Both of these applications use the OSC (Open Sound Control) protocol, which is pretty easy to work with. You can emulate button presses with it and even send accelerometer data. After data is transmitted to your computer over Wi-Fi, you have to write a simple application to process it. I chose to use the rapid prototyping tool Max/MSP (www.cycling74.com). The free PureData (http://puredata.info) would also have worked. Both of these can handle the OSC protocol. The output of this application will be a few commands such as “Turn right,” “Turn left,” “Go forward,” “Go backward.” It’s completely up to you what commands you implement, as it depends on the type of your R/C car (see “Hacking into the R/C Controller,” later in this hack). In this hack, we used a continuous track (steers like a tank) R/C car. You also have a choice as to how you want to drive the car: button presses or the motion of the accelerometer. The application will need to send its commands to a microcontroller. I chose an Arduino controller, which is very popular and has a large community for support. To talk to Arduino, the application uses a USB connection and sends commands as strings using a USB serial port protocol. The Arduino program (called a “sketch”) then sets voltage on some of its pins, depending on which command it receives. For example, the Arduino program has a variable named “Go forward,” which corresponds to a particular pin on the microcontroller. If “Go forward” is set to true, the microcontroller will set the associated pin to HIGH (+5V). If it is false, the pin will be set to LOW (0V). Using this with a transistor, we can emulate button presses on the R/C car’s controller. Even though there are joysticks on many R/C controllers, joysticks are nothing more than a set of buttons. For example, left and right are simply controlled by a pair of buttons (as are forward and backward). Here’s the list of parts you’ll need: • •

• • •

Cheap R/C car (we used an old Tyco Rebound 4x4) Arduino USB board such as the Duemilanove (available from MAKE at www.makershed.com/ ProductDetails.asp?ProductCode=MKSP4 or from http://arduino.cc) Wi-Fi-enabled PC or Mac 4 NPN transistors (we used C547C) A few wires

Make sure that your iPhone and your computer are on same Wi-Fi network. Download the OSCemote (Figure 12-133) application from the App Store ($5). Run OSCemote, tap More, then Settings, and enter your computer’s IP address (its Bonjour hostname may also work) as the OSC Host, and 7000 as the port (Figure 12-134).

chapter 12 - Control the Physical World from Your iPhone

413

Figure 12-133. OSCemote

Figure 12-134. OSCemote settings

To run the sample application, you’ll need the latest Max5 Runtime, which is available for free (http://cycling74.com/downloads/max5) for your platform. Go to http://code.google.com/p/ iphonerccar/downloads/list and download and unzip the latest copy of the remote control software. Run either Continuoustrack.maxpat or Standarttype.maxpat, depending on the type of your R/C car. Continuoustrack.maxpat is for tank-style cars, where each side is independently controlled, and Standarttype.maxpat is for cars that have steering and acceleration.

While you are playing with this hack, you might want to disable Auto-Lock on your iPhone

(otherwise, it will keep switching off and dropping the connection between OSCemote and Max/MSP). Go to the iPhone Settings, tap General, then Auto-Lock, and set it to Never. You probably want to re-enable Auto-Lock when you are done using OSCemote.

Set the input port to the same value that you set in OSCemote (7000). Now you should see some movement in the accelerometer area. You can test it by switching to the Buttons screen on OSCemote and tapping buttons. The symbols in the lower-left corner will blink, based on how you move the controls. You can also switch to the Accel screen, toggle the accelerometer on, and then wiggle the iPhone. The control scheme is shown in Figure 12-135.

If you tried out the accelerometer feature, please turn it off for now, as it will interfere with the input messages coming from the buttons.

414

iphone hacks

HACK # 12.16 Figure 12-135. Controller scheme

Now you need to download SimpleMessageSystem for Arduino. It’s available from www.arduino.cc/ playground/Code/SimpleMessageSystem. Download it and install it. Note that the read_me.pdf file included with the download is out of date. Instead of copying the SimpleMessageSystem folder into the lib/targets/library/ subdirectory of the Arduino installation, put it into hardware/libraries/. After you’ve installed SimpleMessageSystem, open the Arduino.pde sketch in the Arduino Integrated Development Environment (IDE). Upload the sketch to your Arduino over USB. Close the Arduino IDE, but leave the Arduino connected to your computer. Return to Max/MSP and choose the serial port to connect to your Arduino (Figure 12-136).

Figure 12-136. Set the serial port (Windows shown to the left, Mac OS X to the right)

chapter 12 - Control the Physical World from Your iPhone

415

Now, rotate the iPhone so that the Home key is to your right and the top of the phone to your left (look ahead to Figure 12-141). Using OSCEmote, switch to the Buttons view, and tap the upper-left button. You should see the LED next to pin 13 blink on the Arduino. If it blinks, you’re good (Figure 12-137). If you want to see more light, slide an LED into the Arduino: short lead (negative, cathode) goes to GND, long lead (positive, anode) goes to pin 13. If it does not blink, make sure that the Arduino is really communicating with Max/MSP (blinking RX and TX). Make sure that you closed the Arduino IDE (because it locks the port for its own use) and try reselecting the serial port in the Max/MSP patch. If you still have problems, you can open a ticket on Google code at http://code.google. com/p/iphonerccar.

Figure 12-137. LED near pin 13

Hacking into the R/C Controller Prepare all four NPN transistors by soldering 10-inch wires to their base pins (this is the center pin labeled “B” that’s bent up, as shown in Figure 12-138). Use 22 AWG wire (often called hook-up wire), because you need it to slip securely into the Arduino pins. Strip the other end of the wires, leaving about 3/4 of an inch exposed.

If you don’t have an R/C car, you might be tempted to use LEDs for all four pins just

to try this hack out. If you do that, be sure to put a resistor (220 ohms or more should be fine) in series between the LED and either the GND or the pin you are using. You do not need a resistor for pin 13 because one is built in to the Arduino board.

Open your R/C car’s remote controller and find switches that are triggered by the joystick controllers. Now, you’re basically going to replace the original switches with transistors. In fact, you don’t have to replace them: it’s possible to have both the transistors and original switches working in parallel, but that depends on you and how clever you feel like being. In the pictures that follow, you can see that I opted to just replace the buttons. The collector pin of each transistor should be soldered to negative (ground) and the emitter pin to positive side of each switch (Figure 12-139).

416

iphone hacks

HACK # 12.16 Figure 12-138. NPN transistor pinout

C

B

E

Figure 12-139. NPN transistor

Find a suitable place to solder one wire to the controller’s ground, because we need a common ground between Arduino and the controller. Because this will go into the Arduino, use a 22 AWG wire that is at least 10 inches long and strip the other end to about 3/4 inch. You can see the four transistors soldered to replace the switches in Figure 12-140, along with one wire coming from each switch (you will connect these to the Arduino digital pins shortly). The wire at the top is the antenna, and the wires at the bottom are the connection to 9V battery (red and black wires), with one wire (white-brown) to make a common ground with the Arduino.

Figure 12-140. Transistors replacing each button

chapter 12 - Control the Physical World from Your iPhone

417

Now, connect the Arduino, with the ground wire going to the ground pin on the Arduino. Again, your choice of pins depends on the type of remote you have (continuous track, on which the left and right motors are controlled independently to steer) or standard (which has a steering control and a forward/reverse control). Figures 12-141 and 12-142 show the two controller configurations for OSCremote. Here’s how to hook the Arduino to a continuous-track controller: • • • •

Left side, forward—Arduino pin 13 Left side, backward—Arduino pin 12 Right side, backward—Arduino pin 11 Right side, forward—Arduino pin 10

Figure 12-141. OSCremote—continuous control

Here’s how to hook the Arduino to a standard controller: • • • •

Turn left—Arduino pin 13 Turn right—Arduino pin 12 Go forward—Arduino pin 11 Go backward—Arduino pin 10

Figure 12-142. OSCremote—standard control

Figure 12-143 shows the final continuous-track circuit wired to the Arduino microcontroller board.

418

iphone hacks

HACK # 12.17 Figure 12-143. Completed wiring

You are ready to power on the remote controller and power on your car. You should be able to control it by your iPhone!

Hacking the Hack Now it’s up to you what you can do with it. If your car supports changing shape or some other button-press function, you can add one more transistor to the original remote control, then change the Max/MSP patch slightly, and you can control that, too. If you’re a more experienced hacker, you can see possibilities other than just controlling an R/C car. If you use relays instead of transistors, you can control lights in your house, or whatever you want. I’ve tried to make the software for the computer as simple as possible—this is just a small taste of what you can do. You can upload your modifications to Google Code for others, if you want, too. You can see videos of the car and other projects using the iPhone at http://josef-prusa.eu/obsah/ blog/iphone-controlled-rc-car-eng.html.

Hack 12.17:

Charge Your iPhone from (Almost) Any Source

Charge your iPhone and iPod touch with any USB port. You may have noticed that some older iPhone chargers (particularly the cheaper models) won’t work with the iPhone 3G. If your charger used the FireWire pins, you’ll be disappointed to know that FireWire has been discontinued in the iPhone 3G and your charger will not work (unless you hack it; read on). This is commonly the case with car chargers, because the car battery supplies a voltage very close to the voltage needed by FireWire, which greatly simplifies the charging electronics. If yours was a USB charger and it now fails to charge your iPhone, it probably wasn’t built to use the signaling protocol that Apple requires from USB chargers, starting with the iPhone 3G. You might think there’s a standard USB charging specification: all chargers should have certain characteristics so that any device built to spec should work with any charger built to spec. While such a specification exists, don’t waste your time on it. The fact is that most device developers do not follow the specification, but instead design their own protocols—and this includes Apple. chapter 12 - Charge Your iPhone from (Almost) Any Source

419

The first-generation iPhone was very forgiving: if there was power on the USB cable, it charged. The iPhone 3G is more discerning. The pins typically used for transferring data (D+ and D–) [Hack #12.14] need to have specific resistors attached that tell the iPhone that this is an Apple-compliant charger. If you are stuck with one of the old incompatible chargers, you still have a few choices, which are conveniently described in this hack.

Buy a Universal Charger with a Dock Connector Passthrough The Kensington 4-in-1 universal charger and Ridax Dock Connector both provide a way to charge from USB while providing a passthrough to the dock connector for the audio and control connections (Figure 12-144).

Figure 12-144. Kensington 4-in-1 universal charger

Buy an Adapter for Your Existing Charger Iogear and Boxwave both make USB adapters that allow the iPhone to charge from any source (Figure 12-145). Scosche makes an adapter that connects to the iPhone dock and accomplishes the same thing [Hack #12.07]. Just add these adapters between your charger and your iPhone, and you should be able to use your charger again. They aren’t too expensive.

Figure 12-145. Boxwave iPhone charging adapter

Build Your Own Adapter You can build your own adapter using a few resistors and a touch of USB cable splicing. The way you charge the iPhone is to feed it 5V on pin 23, ground on 16, and resistors to D– (25) and D+ (27). D+ and D– are the pins that normally carry the USB data transmission [Hack #12.14]. There

420

iphone hacks

HACK # 12.17 are two valid voltage dividers that you can connect to D+ and D–, depending on how much current you want your iPhone to draw from your charger:

1. 2.

Two resistors, 500 mA (0.5 ampere) Four resistors, 750 mA (0.75 ampere)

Method 1 is the cheapest, easiest, and most compact. It only requires two resistors set up in the network as shown in Figure 12-146. This method gives you a current of 500 mA.

Figure 12-146. 500mA sense resistors

You need to choose values for R1 and R2 between 50K to 100K (50 to 100 kilo-ohms—each, not combined). Varying resistor sizes will work, as long as R1 and R2 are the same—and if the resistance is not too great or to small, you should be OK. Method 2 is to use a four-resistor network configured as shown in Figure 12-147, which gives you a current of 750 mA.

Figure 12-147. 750mA sense resistors

In this case, R1 and R2 must be 50K, R3 must be 150K, and R4 must be 100K. This tells the iPhone to draw up to 750 mA amps of current from your charger. If your charger cannot handle that much current, then you may want to use the first method, which consists of two resistors. But what if your charger doesn’t supply 5V? (You’d have this problem with a FireWire charger.) Read on for a solution.

chapter 12 - Charge Your iPhone from (Almost) Any Source

421

Make a 3G Adapter Cable to Charge via FireWire The goal of adapting the FireWire cable is to convert the FireWire voltage (often 12 volts) to the 5 volts needed for USB. This technique works for many chargers and power sources, including battery backups and the like. Your goal is to obtain a smooth and stable 5-volt source, and then add the resistor network described previously to the end of it. Voltage regulator chip By far, the simplest and easiest method is to use the LM7805 chip. Available from any electronics supplier, including RadioShack, it can take any voltage up to 35V and reduce it to a very steady stable 5V. It will supply up to 1 amp of current, which is more than enough for the iPhone. It’s a dream, right? Well, there is a catch. The 7805 wastes all the extra juice: if you feed it 12–15V from a car battery through the cigarette lighter adapter, that means 1/3 of the juice goes to your iPhone, and 2/3 goes into heat. This also means your 7805 chip can get very hot, to the point of becoming a fire hazard. To avoid that danger, you’ll have to install a heat sink to dissipate the heat. You’ll also need to ensure that your chip never gets above 150˚C (300˚F), and it would be best to stay below 100˚C (212˚F). That might mean quite some heat sink. This is a quick and dirty source of power and isn’t really practical, but it does make a great demonstration. The circuit is shown in Figure 12-148, using the iPod breakout board to demonstrate. If you don’t have a breakout board handy, you can use an iPod dock connector if you have one lying around [Hack #12.14].

Figure 12-148. Charging the iPhone 3G with 12V

GND

12V PodBreakout dock connector breakout board

.75 A resistor network 7805 voltage regulator with heatsink

422

iphone hacks

HACK # 12.17

Hacking the Hack Once you have the tools described in this hack under your belt, there are myriad combinations you can apply in order to power your iPhone in any environment—even from solar cells. We’ll run through one last example of crossing a “wall wart” FireWire charger with a 3G USB car charger to create a wall wart charger for your iPhone 3G. This hack will require some soldering skill and isn’t for the faint of heart. You’ll need the following: • •

A soldering iron and some solder. A USB car charger. Make sure that it works before beginning by charging your iPhone in the car. You might want to use a charger that provides multiple USB outlets. You can modify one output for the dock cable, and keep the other outlet for charging other USB devices. A dock extender cable. A number of companies produce dock extender cables. CableJive and Ridax both sell dock extender cables on their websites. Make sure that the cable you order has all the connections you want. For example, the CableJive cable doesn’t provide audio inputs to the phone. If you need only audio out and iPod control, both cables should be fine. We’ll use the Ridax cable for this example, because it has all the connections we want; plus, the flat-pack cable will make it easier to determine which wires to cut.

The basic idea here is to take the 12V source from the original FireWire pins and run it through the USB charger to produce a 5V output. (Internally, the USB charger most likely has a switched-mode power supply.) We can then run the 5V power to the USB pins on the output side. Essentially, we’re going to hard-wire the USB conversion into our adapter cable, while making sure not to change the audio or control wires. It’s probably a good idea to remove the cable before attempting any data transfers or sync operations. First, find and cut the following wires: • • • • • •

FireWire power (pins 19 & 20) FireWire ground (pins 29 & 30) USB power (pin 23) USB Data + (pin 27) USB Data – (pin 25) USB Ground (pin 16)

dd

More pinout information can be found at: http://pinouts.ru/Devices/ipod_pinout.shtml and [Hack #12.14]

Open the casing on your USB charger, then follow these steps:

1. 2. 3. 4. 5. 6.

Desolder the original power wires, noting which spot was connected to power (the tip of the charger) and which was connected to ground (the side prong). For now, we’ll reuse the charger casing, but you may want to put it in a different housing if it’s too bulky. Cut the FireWire power (19, 20) wires on the dock cable. Solder the wires coming from the female end to the 12V input on the charger. Cut the FireWire ground wires (29,30) on the dock cable. Solder the wires coming from the female end to the ground input on the charger. Make sure that the USB charger power and ground are connected to the female dock connector. At this point, you might want to test your cable. Connect the female end to your iPod connector, and attach your iPhone or a USB device to the charger output. Make sure that the USB output is working properly, and recheck your work if it isn’t.

chapter 12 - Charge Your iPhone from (Almost) Any Source

423

dd

If necessary, add the USB voltage divider described earlier in this hack to the USB output of the charger. You may need to remove the USB connector to make room for the new wires.

7. 8. 9. 10.

Cut the USB power (23) and ground (16) wires on the dock cable Solder the wires coming from the male ends to the USB power (1) and ground (4) pins on the charger. Cut the USB D+ (27) and D- (25) wires on the dock cable Solder the wires coming from the male end to the D+ (3) and D- (2) pins on the charger USB output.

Now you need to seal the USB wires coming from the female dock connector, making sure that none of them are touching each other. If you plan on using your cable year ’round, or in a humid environment, you might want to use something that will form a watertight seal. Optional: ground the remaining FireWire wires coming from the male connector. This will ensure that the iPhone doesn’t see any floating signals on the unused FireWire pins. If you chose not to ground these pins, make sure that they are sealed. Now it’s time to wrap it up:

11. 12.

Close the charger case, making sure not to crimp the new wires. Secure the new wires to the connector to make sure that they do not get pulled out, and make sure that there are no exposed connections.

Plug the adapter into your original dock connection, and connect your iPhone to the other end. Verify that it is charging, and that your audio and control connections still work. If you used a dual-outlet USB charger, you should be able to charge other USB devices from your adapter cable as well. ——Zack Gainsforth & Christopher Kurpinski

Hack 12.18:

Connect Your iPhone to a Serial Port Using a Dock Connector

With the right adapter, your iPhone can talk to serial devices via the dock connector. Serial has been the staple low-speed communications protocol for decades. Because the iPhone is the new overlord of connectivity, obviously you’ll want to add RS-232 to its repertoire (or USBSerial if your computer does not have legacy ports). The problem is that the iPhone has only a 3V TTL connection built into the base. However, a bit of fancy adaptation allows you to conjure up a serial connection anyway. You’ll need your wire strippers as well as a converter cable. If your serial device doesn’t draw too much power, you can even power it from the iPhone! The parts you’ll need are: •

424

iphone hacks

A 3.3V TTL-to-RS-232 cable, part number MCU-026-172 from www.superdroidrobots.com or a 3.3V TTL-to-USB cable, such as part number 768-1016-ND from www.digikey.com. If you’re connecting to another 3.3V TTL device—such as a microcontroller—this is not needed.

HACK # 12.18 •

An iPod USB sync cable, such as part number IPD-3 from All Electronics www.allelectronics.com or the PodBreakout from SparkFun Electronics (www.sparkfun.com, part number DEV-08295) Spudgers for opening the cable plug [Hack #12.09]

The first task is to rewire the USB sync cable so that it uses the iPhone’s serial pins rather than the USB pins [Hack #12.14]. To do this, you will have to open up the iPhone plug using a spudger, as shown back in. There you’ll also see the process of rearranging the pins in a dock connector. Once you have completed the steps in [Hack #12.14], your next step is to use a pair of needle nose pliers to remove the pins from their existing seats and push them back into the pinout, as listed in Table 12-2. Table 12-2 iPhone serial and power pins

Pin Number

Color

Purpose

1

White/Yellow

Ground

12

Black

iPhone Serial TX

13

Green

iPhone Serial RX

18

Red

iPhone 3.3V power

Pin 1 is the pin farthest to the left. You can also find pin 1 by holding your iPhone in your left hand face up, and then plugging in the cable with your right hand. The pin closest to you is pin 1. Pins 2, 3, and so on are found by counting away. Pin 30 is the farthest to the right. Pins are pulled and reinserted with your fingers, or with needle-nose pliers, as in Figure 12-149.

Figure 12-149. Rearranging the pins

Next, snip the USB end off the sync cable and strip the wires. Then snip the end off the RS-232 cable (if you are using the USB/TTL cable, it should come with stripped ends) and place a section of heat-shrink tubing over one of the cables. Next, solder the cables together, matching wires by

chapter 12 - Connect Your iPhone to a Serial Port Using a Dock Connector

425

color. Note that yellow matches with white. If you have any doubt about which wire goes with which, you can consult the datasheet for the RS-232 or USB/TTL cable. It is helpful to snip the RS-232 or USB/TTL cable at the very end, as you may encounter unused wires (with different colors), which can be mildly confusing. After soldering, wrap each wire with electrical tape so that they don’t short out against one another. Pull the shrinkwrap over the joint, and heat it up with a hot air gun. Your final result should look like Figure 12-150.

Figure 12-150. iPhone serial to RS232

Talking to the iPhone Once you’ve done all this, you’re going to need some software to talk to it. To write programs to work with the serial port on an iPhone, you’ll need the source code at http://devdot.wikispaces. com/Iphone+Serial+Port+Tutorial, which you can build with one of the development environments in Chapter 11.

Hack 12.19:

Remote Control Your iPhone or iPod touch with the Dock Connector

Make an iPhone- and iPod-compatible docking station. Ever since the second generation of iPods, there has been the option to control the iPod through an external interface so that you could remotely skip songs and use other functions. This feature still exists in today’s iPhone. In order to control your iPhone externally, we’re going to use the serial port pins that you learned about in [Hack #12.14] and [Hack #12.18] in the dock connector. This time, though, we’re going to emulate one of those iPhone docking stations that you find in boomboxes or cars. The iPhone is smart, in that it detects when it is being controlled serially, and switches the audio output from the 426

iphone hacks

HACK # 12.19 headphones to the bottom plug. This feature is useful for docking stations, because you just set your iPhone on the station and it handles both communication and audio (and charging too).

If you want to try adapting this hack for use with a microcontroller, be careful that you

match voltages correctly, or something will fry. Because the iPhone exposes TTL serial, you could bypass the TTL-to-RS-232 or TTL-to-USB adapter entirely if you connect the iPhone directly to your microcontroller. However, the iPhone uses 3.3V signaling, so if you are using a microcontroller that uses 5V (or 1.8V), you’ll need a level shifter such as the $1.95 Logic Level Converter from SparkFun Electronics (www.sparkfun.com), part number BOB-08745.

You’ll need the following: • •

• • • • •

An PodBreakout breakout board, part number DEV-08295 from www.sparkfun.com A 3.3V TTL-to-RS-232 cable, part number MCU-026-172 from www.superdroidrobots.com, or a 3.3V TTL-to-USB cable, such as part number 768-1016-ND from www.digikey.com An audio jack such as part number 274-141 from RadioShack, www.radioshack.com, or part number PRT-08032 (3.5 mm jack) and PRT-08827 (audio jack breakout board) from SparkFun A breadboard. A 500K (500 kilo-ohms) resistor, or multiple resistors that add up to 500K 22-gauge wire A soldering iron Serial debugging software, such as wSHDCOM on Windows (http://wshdcom.exor.hr); you can use any serial comm/modem program, as long as you can paste and send binary strings.

You are going to assemble the setup shown in Figure 12-151.

Figure 12-151. iPod dock remote control

The first step is to solder up your PodBreakout board. Using 22 gauge wire, strip 1/2 inch or so from each end, and solder one end into pins 1-4, 11-13, 18, 21, and 30. You can also solder other pins if you wish to use the same PodBreakout for other projects such as the USB charger [Hack #12.17]. As an alternative to making your own wires, you can purchase breadboarding jumper wires and use them instead. These are just 22 gauge wires, precut and prestripped. Now you need to connect everything on the breadboard, as shown in Figure 12-151. Connect the serial ground to the iPhone breakout ground (pins 1 and 11). Leave pin 2 separate, as that is audio ground and does not need to match the other grounds. You will obtain better audio quality this way.

chapter 12 - Remote Control Your iPhone or iPod touch with the Dock Connector

427

Connect the serial cable into pins 11–13 and 18. The pinout for the RS-232 and USB TTL cable is shown in Table 12-3. Table 12-3 Cable pinouts

PodBreakout Pin Number

USB/TTL Cable Color

RS-232 Cable Color

Purpose

11

Black

White/Yellow

Ground

12

Yellow

Black

iPhone Serial TX

13

Orange

Green

iPhone Serial RX

18

No Connection

Red

iPhone 3.3V power

Audio The audio jack connects to pins 2–4. You will need to open up your jack and solder 22 AWG wire to it. Then you can plug these wires into the breadboard according to the pinout in Table 12-4. Table 12-4 Audio pinout

Pin

Purpose

2

Audio ground

3

Audio left ear

4

Audio right ear

dd

Old iPods know when they are connected to a docking station, because of a 500K resistor placed between pins 21 and 30. This resistor is not strictly necessary for your iPhone, but if you add this, then your docking station will be fully backward-compatible with iPods, too. If you don’t have a 500K resistor, you can usually find a combination of two resistors that produce the required value.

Because this is an iPhone and not an iPod, as soon as you plug it in, you will get the message shown in Figure 12-152. You can choose “Yes” or “No” as you see fit. Rest assured: the protocol works fine on the latest iPhones. We usually select “No;” it will still work.

Figure 12-152. Just say “No”—it will still work

428

iphone hacks

HACK # 12.19

Schematic Putting everything together, this is the electrical schematic you should build (Figure 12-153). Note that the TX and RX are from the perspective of the iPhone; you can verify the pinouts at [Hack #12.14]. Thus, TX (pin 12) goes to the RX of the PC or device you’re connecting to, and RX (pin 13) goes to the TX of the PC or device you’re connecting to.

Figure 12-153. iPhone dock remote schematic

Serial commands OK, so now you’ve built it. How do you control it? First, you need a serial program that allows you to send hexadecimal sequences to your serial port. One example is wSHDCOM, which works under Windows. Next, configure it to run at 9600 baud, 8N1. Now you’re going to use serial commands to control it. The protocol is nicely documented at http://stud3.tuwien.ac.at/~e0026607/aap/ipod_aap.html, but just to get you started, we’ll give you here the sequence to start playing whatever music happens to be on your iPhone. First, switch to accessory mode: FF 55 03 00 01 04 F8

You should get no apparent response from the iPhone except that if the screen is still lit, you will see a display that says “Accessory Attached.” So, just to make sure everything is working, ask for the iPhone name: FF 55 03 04 00 14 E5

You should get a response containing an ASCII string with your iPhone name in it. In my case: FF 55 0A 04 00 15 69 53 6D 61 73 68 00 78

(Bonus points: What’s my iPhone name?) chapter 12 - Remote Control Your iPhone or iPod touch with the Dock Connector

429

If that passes, you now give it a command to select playlist #0, which contains all songs on the iPhone: FF 55 08 04 00 17 01 00 00 00 00 DC

You should get a response: FF 55 06 04 00 01 00 00 17 DE

Now tell it to switch to the playlist that you selected and start playing: FF 55 07 04 00 28 00 00 00 00 CD

You should get a response: FF 55 06 04 00 01 00 00 28 CD

And music should start playing! One last command you might want is the play/pause command: FF 55 04 04 00 29 01 CE

Now that you’ve made the connection, you can write programs on your computer—or microcontroller—that control the iPhone by sending commands like these over the serial port.

Hack 12.20:

Read Signals from an Infrared Remote Control— Without Jailbreaking!

You can receive infrared input on your iPhone without jailbreaking, using the audio input jack. Although numerous one-off hacks connecting all sorts of devices to the iPhone have been posted on blogs and YouTube, the problem with these approaches is that they usually use the dock connector [Hack #12.18] and thus cannot be reduced to commercial products until the iPhone 3.0 operating system is released. However, there is an I/O (input/output) port on the iPhone just waiting to be used: the headphone/ microphone port [Hack #12.21]. If you think about it, people have been squeezing over 50Kbps (kilobits per second) out of phone lines, and they have far less fidelity than the iPhone’s sound chip. And Apple’s SDK works fine with audio input and output...no jailbreaking required!

dd

You can find the source code for the application as well as the schematic at http://perceptdev.com/labs/iphonehacks.

For this demonstration hack, we’ve wired up a simple circuit that takes infrared pulses and converts them to a sound wave. Then we’ve written code to recognize the signals from a well-known remote: the IR (infrared) remote that comes bundled with most Macs.

430

iphone hacks

HACK # 12.20 What you’ll need: • • • • • • •

A 38kHz infrared receiver (Figure 12-154), part number PCM-1 from www.allelectronics.com A 1K (1 kilo-ohm) resistor (color code: brown-black-red) A 220K resistor (color code: red-red-yellow) One electrolytic (cylinder) capacitor in the 47–220uF range One electrolytic capacitor around 10uF One 4-AA battery holder Four 1.2V AA rechargeable batteries

Figure 12-154. A 38kHz infrared receiver

Figure 12-155 shows the pinouts of the IR receiver. It is quite simple: you connect it to 5V (pin 2) and ground (pin 3), and it will output a signal on pin 1.

Figure 12-155. IR pinout

Figure 12-156 shows a close-up of the breadboarded circuit for this hack. Pins 2 and 3 of the IR receiver are connected to 5V and ground, respectively. A capacitor (I used 10uF) is put across ground and 5V to stabilize the input from the batteries. When you point a remote at the IR receiver and press its buttons, this creates a signal in the 5V range on pin 1 of the IR receiver, which is much too hot for the iPhone microphone circuit. So we pass pin 1 (row 2) of the IR receiver through a 220K resistor (rows 2 and 8), to the 1K resistor (rows 8 and ground), which then goes to ground. Where these two resistors meet (shown as row 8 in Figure 12-156), they join a 47uF capacitor. The other side of the 47uF capacitor provides the lowered signal that can be safely put into the microphone port of the iPhone.

chapter 12 - Read Signals from an Infrared Remote Control—Without Jailbreaking!

431

Figure 12-156. Close-up of the breadboarded infrared circuit

You’ll need an audio splitter [Hack #12.14] and a battery pack (four 1.2V rechargeables will give you 4.8V, which should work). You can see the complete circuit in Figure 12-157.

Figure 12-157. The completed IR circuit

Figure 12-158 shows the demo application. The source code for this application and libraries that you can incorporate in your own application can be found at http://perceptdev.com/labs/ iphonehacks. When you press any button on the IR remote while it’s aimed at the IR receiver, the corresponding button will light up (Figure 12-158).

432

iphone hacks

HACK # 12.20 Figure 12-158. Pressing the middle button

If you click the pulse log button shown in Figure 12-159, you’ll see a numerical readout of the different pulses. If you use a different remote control, you can watch those numbers to “learn” new remotes and alter the source code to recognize your new remote (Figure 12-160).

Figure 12-159. Pulse log

Figure 12-160. Pressing middle button

chapter 12 - Read Signals from an Infrared Remote Control—Without Jailbreaking!

433

dd

You can find out more ways to capture signals in the world with the microphone from similar hacks at:

http://wiki.laptop.org/go/Measure http://wiki.laptop.org/go/Measure/Start#How_to_connect_sensors_.28

Hack 12.21:

Connect a Serial Device to Your iPhone— Without Jailbreaking!

Connect all kinds of hardware to an iPhone using the headphone jack as a serial port. The iPhone has a modem. Did you know that? Well, not quite, but when you’re done with this hack, it will. With a little hardware wrangling, you can build a device that interfaces with your iPhone via the microphone/audio jack and can send 1200 baud serial data both ways. Although there are a number of ways to get data into and out of the iPhone—the dock connector, Bluetooth, the camera and screen, and Wi-Fi—none of these are well suited for simple, low-speed bidirectional communication with inexpensive components. Plus, several of these are simply inaccessible from Apple’s SDK. The audio port, however, is accessible from the SDK—both playing audio and recording it—and thus does not require a jailbreak. The demo applications and source code for this hack can be downloaded from www.perceptdev.com/labs/iphonehacks and built by any registered iPhone developer. We start with a souped-up microcontroller, the Cypress PSoC (Programmable System on a Chip). It exposes a UART (serial port) on one side, and talks to your iPhone using FSK (frequency-shift keying), the same technique used on some of the first modems (like the old 300 baud modems). Frequency shift keying is a system that uses alternating analog signals to send information: for example, in binary FSK, a tone of 8000 Hz (hertz) might signify a digital 1, and 4000 Hz digital 0. We chose these two frequencies for this project because:

1. 2.

Our sound must be easily played and recorded through the iPhone audio circuitry. If we choose harmonic frequencies (8000 Hz = 2 * 4000 Hz), then we can use a simple method to decode the signals and make this a weekend hack instead of a weeklong hack.

The Circuit You’ll need the following electronic components. Most of the components cost less than $20; the 5V UART is the most expensive part, at around $30: • • • • • • • • •

434

iphone hacks

Cypress PSoC: CY8C29466-24PXI (http://mouser.com or www.digikey.com part #428-1586-ND) Cypress PSoC MiniProg USB programmer: CY3217 (http://mouser.com or www.digikey.com) Breadboard (a solderless breadboard would work) Three 1K resistors (color code: brown-black-red) One 220 K resistor (color code: red-red-yellow) One 0.1 uF (microfarad) ceramic capacitor (should be labeled “104”) One 0.2 uF capacitor; two 0.1uF (104s) in parallel will work A pair of iPhone headphones that you don’t mind destroying 5–9V power source (a 9V battery is fine)

HACK # 12.21 •

• •

LM7805 voltage regulator, unless you are using a steady 5V power source (Digikey part# LM340T-5.0-ND) 5-pin male 0.100 K.K. header (Digikey part # WM4203-ND) A 5V UART such as the TTL-232R cable (www.ftdichip.com/Products/EvaluationKits/ TTL-232R.htm)

Build the circuit pictured in Figure 12-161. You should get the results shown in Figures 12-162 through 12-165, which show the project from several angles.

Figure 12-161. FSK circuit schematic

If you look at Figure 12-161, you’ll see two inputs. X3-1 and X3-2 connect to a UART (the FTDI USB to TTL serial cable) that you can talk to over a serial connection, such as a PC running HyperTerminal or another serial terminal program (such as screen on Mac OS X/Linux or minicom on Linux). You may need to download a driver for the FTDI cable from www.ftdichip.com/FTDrivers.htm. X4-1 and X4-2 on the right side of the circuit are for the next hack [Hack #12.22]. The same basic circuit is used for both hacks, just with different firmware. The top of the schematic shows the wiring that connects to the headphone jack to plug into the iPhone. The bottom left of the schematic shows the header pins that connect to the UART programmer itself.

chapter 12 - Connect a Serial Device to Your iPhone—Without Jailbreaking!

435

Figure 12-162. FSK circuit—top view

Figure 12-163. FSK circuit—top down

GND

Serial Header

Keyboard Header

[Hack #12.21]

[Hack #12.22]

Pins 12, 27

GND, Pin 18

TX

9V

Figure 12-164. FSK circuit—isometric view

436

iphone hacks

PSoC port

RX

GND, IRDA_IN

iPhone Headphone Plug

HACK # 12.21 Figure 12-165. FSK circuit—bottom

Figure 12-166. FSK circuit, with PSoC programmer and battery attached

You will find it easiest to make the connection to your audio/microphone jack by cutting up an old pair of iPhone headphones and wiring the plug direct to your breadboard.

Programming the Cypress Chip You will need a Cypress programming system. The baseline, simplest programmer is the CY3217 part listed earlier in this hack (Figure 12-166). If you are really interested in spinning projects of your own with this processor family, you’d be better off dropping the greenbacks to purchase an ICE (in-circuit emulator) that allows to you debug the hardware. It is a must for development, but overkill for simply programming a chip. You can find information about the ICE and how do develop your own projects at www.psocdeveloper.com/getting-started.html. You will also need the PSoC Designer software at: www.psocdeveloper.com/tools/ psoc-programmer.html (Figure 12-167). You can then download the source code for this hack, both for the iPhone application and for the PSoC from http://perceptdev.com/labs/iphonehacks.

chapter 12 - Connect a Serial Device to Your iPhone—Without Jailbreaking!

437

Figure 12-167. PSoC Programmer software

Unfortunately, the Cypress PSoC development environment is Windows-only. However, it is free to download. It includes its own C compiler, which is also free (but limited in functionality: you will need to spend a lot of money to obtain the fully optimized version). This hack was actually developed on a Mac using Windows running under Parallels Desktop as well as VMware Fusion, so you could run it on your Mac if you don’t mind purchasing VMware or Parallels as well as a Windows license. There are few devices on the market like the Cypress chip. It’s not just a microcontroller. It is a combination microcontroller, FPGA (Field Programmable Gate Array), and analog device. Cypress calls it a “mixed signal array.” Whereas an FPGA has software configurable digital hardware, the Cypress chip also has software configurable analog hardware. An equivalent design to this application would have about 10 op-amps, and a bunch of other discrete components on the board, as well as an FPGA that you would have to program. Incidentally, this is the reason why the Cypress is so good for analog audio processing: it really allows you to squeeze a whole circuit board onto one chip. For example, this hack (UART to FSK) was converted to keyboard-to-FSK [Hack #12.22] in about a day. The hardware for both is exactly the same, requiring you to just upload a different program to the chip. To flash the chip, you’ll need to use the PSoC Programmer, shown in Figure 12-166. You’ll also need the firmware for this hack, which you can download from www.perceptdev.com/labs/iphonehacks. Plug the USB end into your computer. If not already installed, install the PSoC drivers, and the PSoC Programmer software (Figure 12-168).

438

iphone hacks

HACK # 12.21 Figure 12-168. PSoC Programmer software

After you start it up, select the correct chip family, the 29x66, CY8C29466 (Figure 12-169). You should see “connected” on the bottom right of your screen if the software and chip are communicating. You can test the connection by clicking Toggle Device Power, and you should see a red LED light up or turn off on the PSoC programmer hardware, and the words “Not Powered” on the bottom of the screen will change to “Powered.”

Figure 12-169. Choose the correct family

Click “file load” to load the firmware file that you downloaded from http://perceptdev.com/labs/ iphonehacks, and then click Program, which will flash the chip (Figure 12-170).

chapter 12 - Connect a Serial Device to Your iPhone—Without Jailbreaking!

439

Figure 12-170. Programming the PSoC

How it Works To build the FSK to UART converter shown in this hack, we used the method described in two papers: •

FSK Generator, Application Note AN2098: www.psocdeveloper.com/docs/appnotes/an-mode/ detail/an-pointer/an2098/an-file/122.html, which describes how to take digital bits and turn them into an FSK audio signal. FSK Detector, Application Note AN2336: www.psocdeveloper.com/docs/appnotes/an-mode/ detail/an-pointer/an2336/an-file/124.html, which describes how to decode the FSK audio signal back into digital bits.

The circuit takes serial from the computer, converts to frequency-shift keying. It takes a carrier signal, such as a sine wave, and modulates it, toggling between 4000Hz and 8000Hz (Figure 12-171).

Figure 12-171. 4kHz to 8kHz frequency-shift keying

You can find the source code used to program the Cypress chip at www.perceptdev.com/ labs/iphonehacks. There you will also find audio files that are canned recordings of serial data modulated with the FSK method presented here. 440

iphone hacks

HACK # 12.21 As a test, you can play these audio files out of your computer, and pipe the audio into your iPhone using the microphone splitter from [Hack #12.14]. One of the audio files has a canned message: “If you can read this, then your system is working!” Like a player piano, you can even see the speed and cadence of the original typing as it plays. The iPhone can even be acoustically coupled—a fancy word for holding the iPhone near a speaker using the microphone on the bottom, without using a microphone splitter. You can simply play some of the sample FSK files from your laptop or desktop speakers, and hold the iPhone, running the FSK application, near the speakers. You’ll have to hold it just right to get a clean decoding, as you can see in Figure 12-172.

Figure 12-172. PC Speakers <--> FSK Application demo

The FSK specifications are: • • •

1200 baud 8-N-1 Bit 1: 8kHz Bit 0: 4kHz

The baud rate to the iPhone is 1266 exactly (intended to leave a little buffer so that a 1200 baud device connected to the FSK circuit never gets jammed). If you treat TX as 1200 baud, you’ll be fine, because the chip will never send anything at a rate faster than 1200 baud. The bytes are sent as ASCII little-endian (LSB/MSB). So for example, “U” is sent as the following 9 bits: bit 0: 4 kHz start bit bit 1: 8 kHz bit 2: 4 kHz bit 3: 8 bit 4: 4 bit 5: 8 bit 6: 4 bit 7: 8 bit 8: 4

Standby is at 8kHz. That is, if you’re not sending data, then emit a constant 8kHz tone.

chapter 12 - Connect a Serial Device to Your iPhone—Without Jailbreaking!

441

You can decrease the sample rate of this audio file significantly in an audio editing program, even compressing it to an MP3, and it will still work. It has been tested to 20kHz at 16 bits, and it was just fine. Theoretically, you could go to 16kHz and retain the information.

Hacking the Hack If you’ve read this far, you probably already have ideas for how to apply this. [Hack #12.22] jumps right into applying this circuit to the holy grail of iPhone device connectivity: an iPhone keyboard. ——Zack Gainsforth, George Dean IV & Damien Stolarz

Hack 12.22:

Connect a Keyboard to Your iPhone— Without Jailbreaking!

Adapt an infrared keyboard for PDAs and type on your iPhone. A number of industrious hackers have achieved what to some is the holy grail of iPhone accessories: a physical iPhone keyboard. But most have done it in a very hard-to-repeat manner, and few have shared the methods they used. This hack attempts to solve both of these problems. For one, it uses the audio port, an Apple-SDK supported method of communicating with an iPhone or second-generation iPod touch. And for another, the source code for the hardware used—both to program the chip, and to run on the iPhone—are publicly available. You can download schematics, code, plans, and a parts list from http://perceptdev.com/labs/iphonehacks. Furthermore, you can purchase new and used infrared keyboards online for less than $10 USD. Thus, with everything needed from [Hack #12.21], you’re looking at potentially less than $75 USD to build a keyboard, chip programmer included (Figure 12-173).

Figure 12-173. Typing on a Targus PDA keyboard into the iPhone

442

iphone hacks

HACK # 12.22 Using a modified version of the iPhone modem Cypress firmware from [Hack #12.21], you can attach an external portable keyboard to your iPhone. We implemented support for two keyboards: a MicroInnovations IrDA Palm keyboard, which had an unusual binary protocol (“scan codes”), due to its unusual keyboard layout (Figure 12-174); and a Targus keyboard, whose scan codes matched a standard PC keyboard. Both were designed for use with a PDA and use a form of infrared called IrDA to send keypresses to a device.

Figure 12-174. MicroInnovations keyboard hooked to Cypress circuit

Rather than worry about building an IrDA receiver, we just wired the IrDA signal directly by soldering leads to both terminals of the IrDA transmitter. This gave us a cleaner signal and simplified development (Figure 12-175). If you wish, you can certainly add an IrDA receiver to the modem and obtain the same functionality.

Figure 12-175. Soldering onto both sides of the IrDA transmitter LED

The schematic for the keyboard hack is the same one described in [Hack #12.21], except now we’re using the header for keyboard in. It is shown again in Figure 12-176 for ease of reference.

chapter 12 - Connect a Keyboard to Your iPhone—Without Jailbreaking!

443

Figure 12-176. The iPhone FSK adapter schematic

To connect the Targus keyboard, you need to snip the red and white wires that lead to the IR transmitter (Figure 12-177).

Figure 12-177. Finding the IR red and white wires

Wires

444

iphone hacks

HACK # 12.22 Then clip these two wires. The white wire from the Targus IR keyboard (not shown) clips to the IRDA_IN pin on the circuit. The red wire from the Targus IR keyboard (not shown) clips to any convenient ground (Figure 12-178).

Figure 12-178. Connecting the keyboard to the FSK circuit

How It Works The IrDA signal on the keyboard essentially “shorts” a voltage (brings it down to zero), which you provide via a 5K (5 kilo-ohm) pull-up resistor. Thus, the standby voltage is 5V (in our case) and the value goes to 0V (short) for brief, 5 microsecond pulses as the keyboard shorts the line. A series of pulses (or lack thereof) indicates what data is being transmitted. (Figure 12-179 shows a single byte sent over the channel.)

Figure 12-179. One byte (start bit + 10001100)

In Figure 12-179, the leftmost bit is the start bit (logic 0, voltage 0). The 8-bit sequence following is 10001100. The absence of a pulse implies logic 1, the presence of a pulse implies logic 0. This is the first byte (first half of the scan code) sent in response to a keypress “u.” chapter 12 - Connect a Keyboard to Your iPhone—Without Jailbreaking!

445

In this configuration, the presence of a pulse indicates a logic 0, and the absence indicates a logic 1. The pulses are sent at 9600 baud. Therefore, in order to read the data sent by the keyboard, you have to do the following:

1. 2. 3. 4. 5. 6. 7.

Using a DigInv block on the Cypress chip, use an interrupt to call a function in your code each time a negative pulse (zero) arrives. Wait for a first pulse. This is your start bit, which signifies the start of a byte. Your function will start a timer that goes for 3/2s of a 9600 baud period (150 microseconds). If subsequent pulses arrive during the timer period, your function notes them. If no pulse occurs, your function is not called. When the timer is up, check to see if the interrupt function was called. If not, that would mean the last bit was a logic 1 (no pulse). If it was called, then the bit was logic 0. Reset the timer for a single 9600 baud period (100 microseconds). Repeat step 4 seven more times. On the last bit (now you have 8), write the byte to the FSK system—which is identical to what you did in [Hack #12.21]. Also turn off the timer, and have your interrupt function wait for another start bit. At this point, you will be in the middle of a stop bit, which is always logic 1, (no pulse, signifying the end of the byte.

Because the keyboard sends data at 9600 baud, the circuit has to buffer data to some extent, even though nobody can seriously type faster than 1200 baud. This is because key presses generate multiple bytes: they’re scan codes, not ASCII. And, because scan codes vary from keyboard to keyboard, you are best off figuring out what they are by pressing keys. Note that both the press and release of a key generate a scan code, as do modifier keys like shift, alt, and control. So a single character typed could generate 6 or more bytes of data. With stop bits, it could be up to over 50 bits for a single keypress. A 120 words per minute typist can type 10 characters per second. Yet even with overhead, 500 bits per second fits into our 1200 baud bandwidth budget. When the keyboard firmware is loaded onto the Cypress chip, it replaces the bidirectional serial firmware from [Hack #12.21]. There is only enough memory on the Cypress to do one-way communication (keyboard to the iPhone) in the current code, but if you optimized it further or used a larger Cypress chip, it would be possible to have keyboard input simultaneously with some sort of serial output to a device. It’s also worth noting that the keyboard uses only the microphone input. Thus, using a simple Y-splitter [Hack #12.14], you should be able to listen to audio while typing.

446

iphone hacks

HACK # 12.23

Hacking the Hack The source code for the Cypress firmware for reading the keyboard is available from www.perceptdev.com/labs/iphonehacks. Because the source code is available, and because kits with the keyboard preassembled are straightforward to produce, the library that adds keyboard support can be integrated into any iPhone application. Thus, a programmer could create terminal programs, note-taking programs, and even full-screen text editors with arrow controls. Given that some old serial mice originally ran at 1200 baud, it’s entirely conceivable that an improved circuit could be produced with both mouse and keyboard support. But with the iPhone being such a nice computer...with a keyboard...it seems like we’re only a few steps away from a mobile PC revolution [Hack #12.23]. ——Zack Gainsforth, George Dean IV & Damien Stolarz

Hack 12.23:

Use Your iPhone to Go Back in Time

The iPhone is a portable personal computer. Everyone with a smartphone has a personal computer in their pocket. But if the iPhone is such a great computer, why are we still carrying around a laptop? There are wireless technologies coming around the corner, such as UWB (“ultra wideband”), that promise to connect devices to screens wirelessly. But until that time, we have [Hack #12.06] to enable our iPhones to connect to monitors. Using [Hack #12.06] combined with [Hack #12.22], we’ve finally “demobilized” the iPhone, taking portable computing to its illogical conclusion (Figure 12-180).

chapter 12 - Use Your iPhone to Go Back in Time

447

Figure 12-180. The iPhone as a desktop personal computer

Enjoy hacking your phone!

448

iphone hacks

HACK # 12.23

12 - chapter 12 - Use Your iPhone to Go chapter Back in Time

449

450

iphone hacks

Index A Access Point Name (APN) settings, 193–195 account balance, 155 address book, autocorrection, 213–214 Address Book, backing up, 64 addresses folder path, 24–26 IP, 223–224, 247–250 router, 247–248 administration, remote server, 233–236 AFP (Apple Filing Protocol), 237–238 AHED, 127–128 AIM, 66–67, 82 Air Sharing, 34, 87 airtime usage, 155 alert duration, 77–79 AllElectronics.com, 402–403 altering voice, 271–272 Amazon Kindle, 121 Anguna, 146 animation, exporting, 104 antenna, performance, 257 AnyDVD, 99 anySIM, 187 APIs API Explorer, 337–339 private, 339–345 APN (Access Point Name) settings, 193–195 AppBackup, 34 AppFlow, 216 Apple Filing Protocol (AFP), 237–238 Appletalk, mounting filesystem, 237–240 Apple TV, remote, 272–273 Apple Universal Dock, 108 Application Notes, 440 applications App Store, 5–6, 19 backgrounding, 255–256 backing up, 280–281 command line scripts, 282–291 databases, backing up, 302–307 force quitting, 40 frameworks, adding, 342–343 hidden classes, adding, 343–344 hiding, 215–217

installation, 19–23 iPhone, developing on, 328–331 jailbreaking, history, 14–17 manual backup, 34–35 manual installation, 323 native, 4 new, viewing, 331–333 overview, 4 private methods, adding, 344–345 repositories, 21–23 SDK, developing with, 316–320 self-signing, 320–322 third-party, 4, 19–23 timeouts, 289–290 troubleshooting, diagnosis, 37–38 virtual machines, developing on, 324–328 web, 4 Applications folder, 25 apps. See applications App Store, 5–6, 19, 81–82 AptBackup, 280–281 Arduino, remote control, 412–419 ARM processor, 6 aspect ratio, video, 89 Asterisk, 165–166, 167–171 AT&T network, 3 audio capture, 106 autocomplete, 222 autocorrection, 213–214 AutoStitch, 128–129 auxiliary input, car, 362 AV cables, 101–102

B background applications, 255–256 tasks, scheduled, 294–302 Backgrounder, 83, 255–256 backing up application databases, 302–307 files, 30–35, 59–64 jailbroken apps, 280–281 locally, script, 284–285 script, launchd, 301–302 to server, script, 285–291 badge, application result, 290–291 Band, 261–262 barring calls, 156

baseband bootloader, 7, 9–10 chip, 6 firmware, 6–8 unlocking, 18–187 bash utility, 284 Bassline, 263 BBinfo, 10 BD+, 96 beejive, 66–67, 80–81, 81–82 Beighley, Lynn, 303 Big Boss, 56–57 binary plist files, 293–294 bin folder, 25 BIOS, troubleshooting, 38 Bio Worm, 145 Bitfield, 101 bit rate, video, 90 BitTorrent files, 279–280 Bladox, 189 blogging by phone, 177–179 Blu-Ray, converting to iPhone format, 95–101 Bonjour, 88 bookmarks, 62 books, 120–128 BookShelf, 124 bootloader, 7, 9–10 BootNeuter, 188 boot screen, custom, 211–213 Bose QuietComfort headphones, 352 BossPrefs, 216–217, 240, 331–333 Boxwave, 348–349, 420 bricking, 6 browsers, access to files, 28–29 buying unlocked iPhone, 184–185 buzz, ground loop isolator, 366–367

C CableJive adapter, 363–364 cables, output, 101–102, 107–108 Calatrava, Antonio, 243 Calico Panorama, 128 call barring, 156 caller ID, 155, 271–272 call forwarding, 156–158, 244 CallMe, 163–164 call waiting, 155 CallWave, 175

index

451

camera close-up lenses, 354–357 external illuminator, 409–412 measuring distances, 266–269 stills, 128–133 video, 133–135 CamStudio, 106 capture, screen, 104–106 car connecting iPhone, 362–368 R/C, controlling, 412–419 carriers logos, 210 restrictions, 182 cartridges, retro game, 137–139 cd command, 229 CDMA (Code Division Multiple Access) standard, 3 cellular data standards, 3, 193–195 certificates, self-signed, 320–321 charging adapters, car, 363–365 building adapter, 420–424 USB port, 419–424 Chicken of the VNC, 222 chip, baseband, 6 chroot, 5 chroot jail, 320 Clarifi case, 356–357 class-dump, 340–342 classes, frameworks, 337–339, 339–345 Classics, 125 Cleartune, 261 clients, IRC, 54 clipboard, email as, 59–62 Clippy, 275–277 close-up lenses, 354–357 cloud, backing up files, 30, 33, 35 codec, 89–90 Code Division Multiple Access (CDMA) standard, 3 code signing applications, 320–322 Colloquy, 54, 84 ColorWare, 214–215 ComicZeal, 125–126 command-line Handbrake, 91–92 scripts, making applications from, 282–291 tools, learning, 229

452

iphone hacks

community support, troubleshooting, 49–50 component AV cable, 101 composite AV cable, 101–102, 107–108 compression, video, 89–90 computers access to files, 24–26 controlling from iPhone, 220–221 controlling iPhone, 221–222 instant messaging, 70–73 iPhone as, 447–448 Secure Shell (SSH) terminal program connection, 222–233 streaming video and music, 110–116 syncing from iPhone, applications, 270 syncing iPhone call log, 308–309 syncing multiple, 109–110 conductive gloves, 369–371 configuration after unlocking, 193–199 connections, external, 246–251 consoles, video game, 137 contact information, xiii Content Scrambling System (CSS), 96 conventions, xii converting Blu-Ray, 95–101 DVDs, 95–101 video, 89–95 copy and paste, 62–64, 275–277 copying email, 62–63 copy protection, DVD and Blu-Ray, 96–99 cores folder, 25 cost, SDK, 312 CradlePoint, 368 CSS (Content Scrambling System), 96 Cucusoft iPod Video Converter Suite, 101 custom autocorrection, 213–214 boot screen, 211–213 hiding apps, 215–217 icons, speed dial, 159–164 ringtones, 200–206 skins, 206–210, 214–215 view controllers, 335–336 Cyberduck, 228 Cycorder, 35, 133–134 Cydia, 20–23

Cypress PSoC (Programmable System on a Chip), 434–442

D daemon tasks, 294–302 Darkfader, 146 databases, backing up, 302–307 debugging launchd scripts, 298–299 delegate class, application, 334 Delta2, 150 demilitarized zone (DMZ), 248–249 desktop files, manual backup, 34 dev folder, 26 DFU (Device Firmware Upgrade) mode, 42, 46–49 DHCP (Dynamic Host Configuration Protocol), 247 Dial2Do, 179 dictionaries, 126–128 digidrummer, 263 Digital Rights Management (DRM), 96 directories filesystem, 24–26 finding, 229 disassembling iPhone, overview, 372–376 iPhone 3G, 384–391 iPhone original model, 376–383 iPod touch, 391–398 disguising voice, 271–272 DiskAid, 24 distances, measuring, 266–269 distribution issues, SDK, 315 DMZ (demilitarized zone), 248–249 DNS, dynamic, 249–250 dock car, iPod integration, 362–365 charging, 420 connector pinouts, 404–409 original, 350–351 remote control, 426–430 serial port connection, 424–426, 426–430 documentation, SDK, 312–313 Dodd, Richard, 357 domain names, 249–250 DOTS iPhone Glove, 371 double-exposure effect, 356 downloading music, 278–280

SDK, 316–317 torrenting, 279–280 video, 278–280 VM, 324–325 YouTube videos, 277–278 DRM (Digital Rights Management), 96 drums, 263–264 dTunes, 278–280 DumpRom, 146 duration, alert, 77–79 DVD to iPod Converter for Mac, 101 DVDFab HD Decrypter, 98 DVDs, converting to iPhone format, 95–101 dynamic DNS, 249–250 Dynamic Host Configuration Protocol (DHCP), 247 dynamic IP addresses, 247–250 DynDNS, 249–250

E ear protection, noise-cancelling, 353 e-books, 120–128 Ecamm, 270 EDGE (Enhanced Data rates for GSM Evolution), 3, 193 editing files, 237–240 Elgato, 93, 100–101 email copy and paste, 62–64 as storage, 59–62 texting, 64–66 to-fax, 251 visual voicemail, 171–175 Yahoo! push, 58–59 emulation, video games Game Boy, 143–144 Game Boy Advance, 145–147 Nintendo, 139–141 output to TV, 361–362 overview, 136–139 PlayStation, 147–152 Sega Genesis, 141–142 Super Nintendo, 144–145 Emulator Zone, 139 encoding DVD and Blu-Ray, 99–101 encryption DVD and Blu-Ray, 96–99 keys, SSH, 229

Enhanced Data rates for GSM Evolution (EDGE), 3, 193 ePSXe, 150 eReader, 122–124 Erica’s Utilities, 274–275, 283 etc folder, 26 EVDO (Evolution-Data Optimized) standard, 3 exporting PowerPoint presentations, 101–108 extending call record database, 305–307 exterior, painting, 214–215 external connections, 246–251 external illuminator, 409–412 eyeMobile KC-1 lens, 356 EyeTV, 116

F Facebook, 82, 177–179 FairMount, 97 FakeBlank, 188 favorites list, phone numbers, 159 Faxaway, 253 faxes machine, printing to, 251–253 receiving, 253–254 feeds, 116–120 Festival-Lite, 274–275 field of view, camera, 128–129 Field Test mode, 158 files backing up, 30–35, 59–64 BitTorrent, 279–280 computer access, 24–26 filesystem, 23–29 finding, 229 folder path addresses, 24–26 hierarchy, 24–26 iPhone file server, 86–88 iPhone firmware (IPSW), 6 Mobile Finder, 26–28 MobileSafari, 28–29 mounting filesystem, 237–240 ringtones, 205–206 skins, 208–209 sound, skins, 210 Yahoo! push storage, 59–62

filesystem mounting, 237–240 overview, 23–29 filming, 133–135 finding files, 229 findme, 241–242 Findmyi, 244 FingerPiano, 259 firewalls, 246–249 FireWire, charging, 419–424 firmware baseband, 6–8, 8–13, 18–19 DFU (Device Firmware Upgrade) mode, 42, 46–49 restoring, 42–45 fisheye photos, 356 flashlight, 409–412 FlickIM, 80 focus, changing, 354 folders path addresses, 24–26 skins, 208–209 force quitting applications, 40 formats e-books, 120–121 video, 89–95 Forsythe, Daniel, 354 forwarding calls, 156–158, 244 port, 247–249 4-track, 262 FPGA (Field Programmable Gate Array), 438 frame rate, video, 89 frameworks hidden, 339–345 viewing, 337–339 Freeman, Jay, 20–21, 56, 133–134, 312 Free RSS Reader, 118 Fring, 168–169 FSK (frequency-shift keying), 434 FSK Detector, Application Note AN2336, 440 FSK Generator, Application Note AN2098, 440 FUSE (Filesystem in Userspace), 240

index

453

G Gabcast, 181 Game Boy Advance games, 145–147 Game Boy games, 143–144 games emulation, overview, 136–139 Game Boy, 143–144 Game Boy Advance, 145–147 Nintendo, 139–141 output to TV, 361–362 PlayStation, 147–152 Sega Genesis, 141–142 Super Nintendo, 144–145 GarageBand music editing, 262 ringtones, 204 gawk utility, 283 G-BANK, 147 Gcast, 180–181 General Packet Radio Service (GPRS), 3 GeoHot, 15, 52 Global System for Mobile communications (GSM). See GSM gloves, conductive, 369–371 glue, conductive, 369–370 GNU Unix shell utilities, 283–284 Google News, 117–118 Google syncing, 62 GotVoice, 175 GPRS (General Packet Radio Service), 3 GPS, measuring distances, 266–269 graphical user interface (GUI), 6 Griffin, 356–357 ground loop isolator, 366–367 GSM (Global System for Mobile communications) codes, 154–158 standard, 3 GUI (graphical user interface), 6 gzip utility, 283

H hackability, versions, 8–13 Hackint0sh, 51–52 Haldar, Sibsankar, 303 Handbrake, 90–92, 99–101 hand-coding UI, 333–336 hard drive, email as, 59–62

454

iphone hacks

hard reset, 45 Hardt, Jamie, 307 hardware Nintendo emulation, 141 SIM card, unlocking, 189–192 troubleshooting, 38–39 unlocking, 185–187 video conversion, 93 headers, frameworks, 339–345 Head First SQL, 303 headphones adapting for original, 348–349 jack, serial connection, 434–442 noise-cancelling, 351–353 pinouts, 399–404 heat, lap, 358 hidden frameworks, 339–345 hiding applications, 215–217 hierarchy, files, 24–26 High-Speed Downlink Packet Access (HSDPA), 3 Hildenbrand, Chris, 146 Hipcast, 181 homebrew games Game Boy, 143–144 Game Boy Advance, 145–147 Nintendo, 139–141 overview, 136–139 PlayStation, 147–152 Sega Genesis, 141–142 Super Nintendo, 144–145 Hörberg, Bertil, 143 Horrible Demon 4, 143–144 Hotz, George, 52 HSDPA (High-Speed Downlink Packet Access), 3 HTTP server, phone as, 245–246

I iBoot, 7, 9 iBrickr, 14 iCal, 307–311 ICE (In Circuit Emulator), 437 iClarified, 53 icons applications, 288–289 speed dial, 159–164 Idid, 321

iDrum music application, 263–264 ringtones, 205 iFixit, 372 iFuntastic, 14 i3gSim, 189–192 iLiberty, 14–16 illuminator, external, 409–412 iLocalis, 243–244 IM. See instant messages, texting images applications, 288–289 boot screen, 211–213 skins, 206–210 IM+Chat, 81–82 iMaracas, 258–259 IMEI display, 158 ImgBurn, 98–99 iMovie, 92 importing call log to iCal, 309–311 incoming caller ID, 155 inetutils utility, 283 infrared keyboard, 442–447 remote control, 430–434 initialization, view controllers, 335–336 Inside SQLite, 303 Insomnia, 256–257 Installer.app, 19–20 instant messages, texting, 66–67, 70–73, 79–83 Instapaper, 119–120 integration, iPod, 363–365 Intelliscreen, 120 Internet, in-vehicle, 368 Internet Relay Chat (IRC), 54–55, 84–85 Iogear, 420 IP addresses, 223–224, 247–250 iPhone developing applications on, 328–331 Dev Team, 15, 19, 50–51 disassembling, original, 376–383 disassembling, overview, 372–376 disassembling, 3G, 384–391 firmware (IPSW) files, 6 Linux, running, 346–347 wiki, 52

iPhone Configuration Utility, 195–199 iPhone Converter, 94 iPhone Modem, 254–255 iPhone Open Application Development, 6 iPhone Video Recorder, 134–135 iphonelogd, 307 iPhoneNewsreader, 118–119 iPhone-optimized web pages, 4 iphoneSimFree, 187 iPod disassembling, 391–398 integration, 363–365 opening tools, 374 IPSW (iPhone firmware) files, 6 IR-909, 263 IRC (Internet Relay Chat), 54–55, 84–85 iRCm, 85 IrDA transmitter, 443 iSimpleSolutions iPhone integration, 365 iSpoof, 271–272 iSSH, 235–236 iToner ringtones, 205 iTunes backing up files, 30–33 device information, 316 remote, 272–273 ringtones, 200–203 syncing multiple computers, 109–110

J jack, headphone, 348–349 Jaiku, 178 jail, 5 jailbreaking benefits, 14 firmware, 18–19 history, 14–17 overview, 4–5 Pwnage, 16–18 QuickPwn, 16–18 unlocking, 185–186 versions, 8–13 javacom, 322 Jing, 104–106 Jivetalk, 80–81, 81–82 JOE editor, 327–328, 329–330

Jott, 177–178 Just Kissed Games, 324

K kaleidoscope effect, 356 Kekus Digital, 128 Kensington 4-in-1 universal charger, 420 keyboard, infrared, 442–447 Keynote, 104 keys, encryption, SSH, 229 Kindle, 121 Kyocera KR-1, 368

L LAN connections, 250 lap heat, 358 laptop, tethering, 254–255 LaunchAgents, 295 launchd, 295–302 LaunchDaemons, 295 learning music, 260 Learning Unix for Mac OS X Tiger, 229 LED, blinking, 412–416 lenses, close-up, 354–357 Lexcycle, 121–122 Library folder, 25 light, low, photos, 130–132 Lightsaber Unleashed, 256 lighttpd, 245–246 Lingon, 299–300 LinkedIn, 82 links, symbolic, 25 Linux, running on iPhone, 346–347 local backup, script, 284–285 location, phone, 241–244 locktable, 187 LogMeIn Ignition, 221 LogoMe, 212–213 logos, carrier, 210 Lomo viewfinders, 354–356 lost phones, 241–244 low light photos, 130–132 ls command, 229 Lynkeos, 130–131

M MacFUSE, 238–240 Macfusion, 238–239 Mac OS X, system software, 4, 42–45

MacTheRipper, 97 magnifying glass lens, 357 Maildash, 65–66 managing network services, 240–241 manual application install, 323 file backup, 30, 34–35 Maplin, 402 Max/MSP, 413 Max5 Runtime, 414 MCC/MNC pair (Mobile Country Code/Mobile Network Code), 187, 189 mdhelper, 32 measuring distances, 266–269 media container, video, 89 media remote control, 272–274 MesaSQLite, 304 messages. See email; instant messages, texting; MMS; texting methods, private, 344–345 microcontrollers, 412–419, 427, 434–442 MicroInnovations keyboard, 443 microphone, switch, 400 migration assistant, Smartphone to iPhone, 271 MiniPiano, 259 mIRC, 54 mirror video output, 360–362 The Missing Sync, 271 mixing music, 263–264 MMS receiving, 68–70, 77 sending, 67–68, 76–77 SwirlyMMS, 73–77 MobileChat, 81 MobileFinder, 26–28, 34, 63–64 MobileInstallation, 322 MobileMe, 33 mobile phone lenses, 356–357 Mobile Studio, 87–88 MobileSafari, 28–29 mobile user, 4 Mocha VNC, 220 model, identifying, 9 modem, faux, 434 modmyi.com, 53–54 modulator, RF, 358–360 Monster adapter, 400–401

index

455

Moore’s Law, 136–137 mounting filesystem, 237–240 multiple computer syncing, 109–110 text messages, 64–66 music applications, 258–265 manual backup, 34 rear seat entertainment, 365–367 ringtones, 200–206 skins, 210 streaming, 278–280 streaming from computer, 110–116 syncing multiple computers, 109–110 MxTube, 277–278 MythTV, 114–115

N nano utility, 283 NAT, 247 native applications, 4 Netatalk, 237 netatalk utility, 283 network configuration after unlocking, 193–199 network-cmds utility, 283 networking backgrounding applications, 255–256 controlling computer from iPhone, 220–221 controlling iPhone from computer, 221–222 external connections, 246–251 managing services, 240–241 mounting filesystem, 237–240 printing to fax machine, 251–253 receiving faxes, 253–254 recovering iPhone, 241–244 remote server administration, 233–236 SSH terminal program connection, 222–233 tethering, 254–255 tracking iPhone, 241–244 trackpad, 218–219 web server, phone as, 245–246 while sleeping, 256–257

456

iphone hacks

news feeds, 116–120 Ng, Patrick, 354–355 NIB file, 336 night photos, 130–132 Nintendo games, 139–141 noise-cancelling headphones, 351–353 note to self, 71 NullRiver Installer.app, 19–23

O Ocarina, 256, 264–265 OOB (out-of-box), 7–8 OOTB (out-of-the-box), 7–8 open toolchain, 312–316 opening tools, 374 OpenSSH, 284 operating system, troubleshooting, 38 Optomo Pico projector, 108 Orb, 113–114 OSCemote, 413 Oulid, Simon, 118 outgoing caller ID, 155 outlets, 334 out-of-box (OOB), 7–8 out-of-the-box (OOTB), 7–8 output to TV, 358–362

P Package and eXtension Library (PXL), 19 painting exterior, 214–215 PanoLab Pro, 132–133 panorama photos, 128–129, 132–133 partitions, 5 passwords, SSH, 229–231 PdaNet, 254–255 PDF books, 124–125 PDRoms, 138 permissions, xii personal computer, 447–448 phones Asterisk voicemail, 165–166 blogging, 177–179 GSM codes, 154–158 mobile phone lenses, 356–357 podcasting, 180–181 ringtones, 200–206 speed dial, 159–164 spoofing, 271–272

translate voicemail to text, 175–177 Twitter, 177–179 visual voicemail, 171–175 voicemail button, 158 VoIP (Voice over IP), 167–171, 257 Vonage voicemail, 166–167 PhoneTag, 175 PhoneView, 270 photography, 128–133, 354–357, 409–412 Photo-JPEG, 93, 106 photos, manual backup, 34 physical computing, 412–419 piano applications, 259–260 PianoChords, 260 PianoChordy, 260 Pico projector, 108 picture messaging, 64, 67–70, 73–77 Pier Solar, 142 Ping.fm, 179 pinging domain names, 250 pinouts, 398–409 PlayStation games, 147–152 pledit.exe, 294 Plist Editor for Windows, 294 plist files, 239–240, 291–294, 299–300 plugs, headphone, 348–349 plutil, 293 PodBreakout, 404, 406, 427 podcasting by phone, 180–181 Poof!, 216 port forwarding, 247–249 PowerPoint presentations, 101–108 preferences, plists, 291–294 prereleasing firmware, SDK, 315–316 presentations, PowerPoint, 101–108 printing, 62, 251–254 private APIs, 339–345 encryption key, SSH, 229 IP addresses, 247 private folder, 26 profiles codec, 90 provisioning, 320 projector, PowerPoint presentations, 101–108 property lists. See plist files

protocols, data, 3, 247–248 provisioning, 320, 321–322 PSoC (Programmable System on a Chip), 434–442 public encryption key, SSH, 229 IP addresses, 247 purchasing unlocked iPhone, 184–185 PureData, 413 push, cloud, 33, 59–62 PuTTY, 224–226 pwd command, 229 Pwnage, 16–18, 188 PXL (Package and eXtension Library), 19

Q QuickPwn, 16–18 QuickTime Pro, 92 quitting applications, 40

R radio frequency modulator, 358–360 Radtech, 403 Randall, Chad W., 324 R/C car, controlling, 412–419 readers, e-books, 120–126 Really Simple Syndication (RSS) feeds, 116–120 RealVNC, 220, 222 rear seat entertainment, 365–367 reassembling iPhone original, 376–383 iPhone 3G, 384–391 iPod, 391–398 RebelSim, 192 rebooting, 41–42 receiving faxes, 253–254 recording music, 261–262 video, 133–135 recovering iPhone findme, 241–242 iLocalis, 243–244 recovery bootloader, 7 mode, 42–45 recurring tasks, 296–299 redirecting calls, 156–158 Remote, 272–273

Remote Buddy, 273–274 remote control Apple Universal Dock, 108 docking station, 426–430 infrared, 430–434 in-vehicle, 365 media, 272–274 R/C car, 412–419 Remote Desktop, 220–221 remote IRC, 84 remote server administration, 233–236 RemotePad, 218–219 repositories, 21–23 reQall, 179 resolution camera, 128–129 video, 89 respring application, 285–291, 327 restarting SpringBoard, 331–333 restoring software, 8, 42–45 results, application, 290–291 reversing updates, 13 RF modulator, 358–360 Ridax Dock Connector, 420 ringtones, 200–206 ripping DVDs and Blu-Ray, 96–99, 101 RoadMovie, 101 Rooms, 85 root user, 4 Rost, Bob, 140 router, 247, 368 RSA fingerprint, 227 RSS feeds, 116–120 rsync utility, 283

S Sack of Flour, 140–141 Sadun, Erica, 32, 55–56, 216, 338 saurik, 20–21, 56, 133–134, 312 Savant, 273 sbin folder, 26 SBSettings, 240–241 scheduled background tasks, 294–302 Scosche charger adapter, 363–364, 420 remote control, 365 scp tool, 323 screen capture, 104–106

ScreenSplitr, 361 scripts, command line, making applications from, 282–291 SDK (Software Development Kit) choosing, 311–316 developing applications, 316–320 overview, 5–6 self-signing, 320–322 Secure Shell (SSH) terminal program connection, 222–233 mounting filesystem, 237–240 remote server administration, 233–236 security, file storage, 88 seczone, 187 sed utility, 283 Sega Genesis games, 141–142 self-signing applications, 320–322 Senuti, 270 serial port connection, 424–426, 426–430, 434–442 server backup, script, 285–291 remote, administration, 233–236 syncing iPhone call log, 308 web, phone as, 245–246 services, network, managing, 240–241 Session Initiation Protocol (SIP), 167–170 7-Chords, 260 ShelfServer, 124 shell-cmds utility, 283 shortcuts, speed dial, 159–162 SiAX, 170 signature, Apple, 187 SimpleMessageSystem, 415 Simplify Media, 116 SIM (Subscriber Identity Module) cards, 3, 154, 182–183, 189–192 simulator, iPhone, 319 SIP (Session Initiation Protocol), 167–170 skins, 206–210, 214–215 Skype, 167–171 sleeping, networking, 256–257 slides, exporting, 102–104 SlySoft, 99 Smartphone, syncing to iPhone, 271

index

457

SMS alert duration, 77–79 instant messaging, 66–67, 70–73 multiple recipients, 64–66 sneakernet, 86 software. See also applications IPSW (iPhone firmware) files, 6 restoring, 8 system, 4 unlocking, 185–189 upgrading, 8 versions, hackability, 8–13 Software Development Kit (SDK). See SDK (Software Development Kit) soldering, 376 Sonos Controller, 273 sound files, skins, 210 sources, e-books, 126 SparkFun Electronics, 370, 404 speed dial, 159–164 SpinVox, 175, 176, 178–179 spoofing, 271–272 Springboard, 4, 206, 331–333 Sprint, 3 spudgers, 372–373 SQLite v3, 283, 302–307 SQL (Structured Query Language), 302–307 SSH mounting filesystem, 237–240 remote server administration, 233–236 terminal program connection, 222–233 standards, cellular, 3 Stanza, 121–122 static IP addresses, 223–224, 247 streaming video and music, 110–116, 277–280 Structured Query Language (SQL), 302–307 Subscriber Identity Module (SIM) cards, 3, 154, 182–183, 189–192 subviews, 335–336 SummerBoard, 206–207 Super Nintendo games, 144–145 support, troubleshooting Big Boss, 56–57 community, 49–50

458

iphone hacks

Freeman, Jay, 56 Hackint0sh, 51–52 iClarified, 53 iPhone Dev Team, 50–51 iPhone wiki, 52 IRC (Internet Relay Chat), 54–55 modmyi.com, 53–54 Sadun, Erica, 55–56 SwapTunes, 109–110 SwirlyMMS, 73–77 symbolic links, 25 syncing call log, 307–311 file backup, iTunes, 31 Google, 62 iPhone to computer, applications, 270 multiple computers, 109–110 Smartphone to iPhone, 271 synthesized music, 263–264 System folder, 25 system software, 4

T tab autocomplete, 222 talking, text to speech, 274–275 TalkShoe, 181 TapDial, 162 Tape Measure, 267 Targus keyboard, 443–445 Taylor, Dave, 229 Telekinesis, 111–113 telephony Asterisk voicemail, 165–166 Asterisk VoIP, 167–171 blogging, 177–179 GSM codes, 154–158 podcasting, 180–181 SIP VoIP, 167–171 Skype VoIP, 167–171 speed dial, 159–164 translate voicemail to text, 175–177 Twitter, 177–179 visual voicemail, 171–175 voicemail button, 158 VoIP (Voice over IP), 167–171 Vonage voicemail, 166–167 Terminal, 227–229

terminal program connection, Secure Shell (SSH), 222–233 remote server administration, 233–236 tethering, 254–255 text, translate voicemail to, 175–177 texting email, 64–66 instant messages, 66–67, 70–73, 79–83 MMS, receiving, 68–70 MMS, sending, 67–68 text-to-speech, 274–275 themes, 206–210, 214–215 third-party applications, 4, 19–23 thread, conductive, 370–371 3G connections, 170–171 thumbdrive, iPhone as alternative, 86 timeouts applications, 289–290 recurring tasks, 297–299 TinyURL, 71–73 tip-ring-sleeve (TRS), 399 T-Mobile, visual voicemail, 171–175 tmp folder, 26 TN3270, 236 Tolbert, Nathan, 146 toolchain open, 312–316 VM, 324–325 tools, 372–374 torrenting, 279–280 TouchCopy, 270 TouchOSC, 413 TouchTerm, 233–235 tracking iPhone findme, 241–242 iLocalis, 243–244 trackpad, 218–219 translate voicemail to text, 175–177 triage, troubleshooting, 37–39 trigonometry, measuring distances, 266–269 troubleshooting, 298–299 applications, 37–38 Big Boss, 56–57 BIOS, 38 community support, 49–50

DFU (Device Firmware Upgrade) mode, 42, 46–49 diagnosis, 37–39 force quitting applications, 40 Freeman, Jay, 56 Hackint0sh, 51–52 hard reset, 45 iClarified, 53 iPhone Dev Team, 50–51 iPhone simulator, 319 iPhone wiki, 52 IRC (Internet Relay Chat), 54–55 launchd scripts, 298–299 modmyi.com, 53–54 operating system, 38 rebooting, 41–42 recovering, 42–45 restoring, 42–45 Sadun, Erica, 55–56 TRS (tip-ring-sleeve), 399 truphone, 170 Tuner 440, 261 tuning instruments, 261 Turbo.264, 93, 100–101 Turbo-SIM, 189 TV input from iPhone, 358–362 PowerPoint presentations, 101–108 rear seat entertainment, 365–367 remote, 272–274 streaming from computer, 114–115 TVersity, 116 TVOut, 361–362 Twitter, 177–179, 241–242, 244

U UART, 434 UICatalog sample application, 317–319, 327–328, 331, 333–336 universal charger, 420 Universal Dock, 108 Unix, 4 unlocking, 6 advice, 183 carrier restrictions, 182 configuration, 193–199 purchasing unlocked, 184–185

SIM (Subscriber Identity Module) cards, 182–183, 189–192 software, 185–189 YouTube settings, 199 upgrading software, 8 uploading video, 134–135 Ureach, 176 URLs, shrinking, 71–73 USB port, charging, 419–424 usr folder, 26

voicemail Asterisk, 165–166 button, 158 translate to text, 175–177 visual, 171–175 Vonage, 166–167 VoIP (Voice over IP), 167–171, 257 VoIPover3G, 171, 257 voltage regulator chip, adapter, 422

V

wallpaper, 209 wall wart charger, 423–424 Wani, 145 WAP (Wireless Application Protocol), 74–75 web applications, 4 Web Clips, speed dial icons, 159–163 web server, phone as, 245–246 web-based video conversion, 94–95 website feeds, 116–120 WeDict, 126–127 WhisperSync, 121 WinSCP, 224–227 WinterBoard, 206–210 Wipeout, 152–153

var folder, 26 var/mobile folder, 26 var/root folder, 26 Veency, 221–222 Venus Multi Game Hunter, 142 Verizon, 3 versions, hackability, 8–13, 18–19 vibrate alert duration, 77–79 video capture, 106 compression, 89–90 converting to iPhone format, 89–95 downloading, 277–278 output cables, 101–102, 107–108 recording, camera, 133–135 streaming, 278–280 streaming from computer, 110–116 syncing multiple computers, 109–110 uploading to YouTube, 134–135 Videora, 94 view controllers, custom, 335–336 viewfinders, Lomo, 354–356 Vine, 220 virginizing, 8, 45 virtual machines, developing applications, 324–328 visual voicemail, 171–175 Vizualogic screens, 366 VM, developing applications, 324–328 VMware, 324 VNC, 220–222 VNCViewer, 222 voice, altering, 271–272 VoiceCloud, 175, 176–177

W

X Xcode, 316–320 XIB file, 336 X-Killer, 149 Xploder, 148–149

Y Yahoo! instant messaging, 66–67, 82–83 push, file storage, 59–62 Yellowsn0w, 188–189 Yessim, 192 Yodio, 181 YouMail, 175–177 YouTube, 102, 134–135, 199, 277–278

Z Zamzar, 94–95 Zdziarski, Jonathan, 6 Zeroconf, 88 ZiPhone, 14–16 ZodTTD, 138 Zophar, 139

index

459

460

iphone hacks

index

461

462

iphone hacks

index

463

464

iphone hacks

Recommend Documents

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (31)

iPhone& iPodTouch Foreword Apple's iPhone isn't just another mobile phone. The iPod touch isn't just another music pla...

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (32)

1800 Products RateD · 130 iPod, iPhone + Apple TV TIPS · 150 iTunes Answers iPHONE BABY · IDESIGN RETROSPECTIVE · AND MO...

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (33)

Check for Updates Make sure you have the latest information!TidBITS Publishing Inc.Take Control of v1.0iPhone ...

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (34)

eBook AvailableiOS Forensic AnalysisLearn forensic methods and procedures for iOS data acquisition and analysisiOS...

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (35)

eBook AvailableiOS Forensic AnalysisLearn forensic methods and procedures for iOS data acquisition and analysisiOS...

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (36)

2008 IPod + iPhoneBUYERS’ GUIDE FROM ILOUNGE.COM1500 PRODUCTS RATED SNEAK PEEKS AT UPCOMING ADD-ONS NEW + USED HARDW...

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (38)

eBook AvailableiOS Forensic AnalysisLearn forensic methods and procedures for iOS data acquisition and analysisiOS...

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (39)

iPhone SDK 3 Programming Advanced Mobile Development for Apple iPhone and iPod touch Maher Ali, PhD Bell Labs, Alcatel-L...

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (40)

iPhone SDK 3 Programming Advanced Mobile Development for Apple iPhone and iPod touch Maher Ali, PhD Bell Labs, Alcatel-...

Our partners will collect data and use cookies for ad personalization and measurement. Learn how we and our ad partner Google, collect and use data.

Iphone Hacks: Pushing the Iphone and iPod Touch Beyond Their Limits - PDF Free Download (2024)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Errol Quitzon

Last Updated:

Views: 5978

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.