Sunday, January 4, 2009

Build your own iPhone quick dialer By Erica Sadun | Published: December 31, 2008 - 01:39PM CT


Earlier today, Jeff Smykil wrote about a series of quick dialer programs that were hitting App Store. He wondered if I could write up a quick how-to showing Ars readers how to write their own. So, here you go. You'll need access to the iPhone Software Developer Kit, and you must have signed up for the $99/year developer license so you can deploy software to the iPhone.

Dialing from the SDK

Making an SDK application dial a phone number requires little more than providing a tel:// URL. Use NSURL's URLWithString function to build this with the phone number you supply:

NSURL *url = [NSURL URLWithString:@"tel://2125551212"];

Once built, tell the iPhone to start the call using the UIApplication openURL: method.

[application openURL:url];

If you want the application to dial upon launch, add these two lines to your applicationDidFinishLaunching: method in your main application delegate. When the application loads, it will automatically redirect control to the dialer. Instantly, you've built a click-to-dial application. Add a nice icon, a unique app identifier, a person's name as the Bundle display name and you're set. Presto, instant dialer application.

Generalizing Dialing

When you want an application to provide single-click dialing with an end-user specifiable phone number, use a Settings bundle to coordinate the phone number with your application. A settings bundle is no more than a folder that's named Settings.bundle with a property list named Root.plist inside.

Here's a simple Root.plist file that stores a single text value named phone_number in the standard NSUserDefaults for your application.








Title
Quick Dialer
StringsTable
Root
PreferenceSpecifiers


Type
PSGroupSpecifier
Title
Quick Call


Type
PSTextFieldSpecifier
Title
Phone Number
Key
phone_number
DefaultValue

IsSecure

KeyboardType
Number
AutocapitalizationType
None
AutocorrectionType
No





And here's what that
preferences screen looks like
in the Settings app.

If you choose to use a user-settable phone number, you'll need to check whether the number exists ([[NSUserDefaults standardUserDefaults] objectForKey:@"phone_number]) and whether it conforms to some sort of test for being a valid number (i.e. 10 digits long, etc). Once it passes those test, you just paste the number onto a tel:// prefix using NSString's stringWithFormat: method, create the URL and open it as already seen above. It's really just that simple.

What about Webclips?

When Jeff first approached me, we chatted about creating telephone-based Web Clips. Webclips allow you to store URLs on Springboard as single-tap icons, and can be created from Safari. Unfortunately, the tel:// variations do not easily lend themselves to bookmarking or webclipping from the iPhone. You can do so (easily!), from jailbroken iPhones but for standard-issue App Store compliant units, you cannot.

I actually tried putting together a project (and spent a good deal of time doing so) that would build webclips from your address book contacts, but I found that the SDK sandbox did not permit me to read from or write to the ~mobile/Library/Webclips folder. So that turned out to be a dead end, at least from an official SDK viewpoint.

What about adding multiple contacts?

The final thing that Jeff and I discussed was in regard to adding multiple contact clips to your home screen. The answer is simple. So long as you give each clip a unique identifier (e.g. com.sadun.call-barbara, com.sadun.call-jacqui), you can add as many of these projects as you'd like. Make sure the bundle display name and icon for each project make it easy to distinguish who you're calling. Other than that, edit the two-line code shown above to place a call to the proper number and you're set.

No comments:

Post a Comment