iPhone Development for Beginners – 2010 Edition

So you want to learn iPhone development. Good for you! It’s an exciting platform with great developer tools and an outstanding community. Let me tell you a bit about the benefits of building an app the right way and show you some great resources to get started.

The most important point: If you want a great application with a user experience you’ll be proud of, build a native application using Apple-blessed developer tools and resources. Apple’s developer tools are outstanding applications and the iPhone frameworks provide useful, battle-tested, mature code that lets you do a lot without reinventing the wheel every time you need to build even basic functionality. Best of all, Apple gives their tools away for free.

Continue Reading…


Flash is My Keeper

Last night, I mused about why Adobe would continue advancing Flash’s agenda when it’s clearly such a bad product. Flash is sluggish, it doesn’t run well on mobile devices and it produces websites that are nearly unusable compared to slick HTML implementations.

I’ve hated Flash for the better part of five years, a bigotry mostly inspired by how poorly it has worked for me as an end-user. It’s even worse for people who need to maintain web sites in Flash, as I later learned professionally. An essential tool for any computer I use more than five minutes is Flashblock for Firefox or the outstanding ClickToFlash plugin for Safari.

Then it dawned on me: If I hate it this much, surely Adobe, who is responsible for maintaining it, must hate it even more. Surely no amount of money is worth this much pain, right? There must be another reason Adobe prolongs this shared internet misery.

Drawing equal parts inspiration from 2001, Terminator 2 and Babylon 5, I present to you: Flash is My Keeper.

INT. CEO’S OFFICE – NIGHT

We’re in a dark, opulent office. Lit only by a small table light, we see SHANTANU NARAYEN, CEO of Adobe, seated at a large desk. He is in shirtsleeves, his suit jacket abandoned elsewhere in the office.

His breathing is thick as he nurses a tumbler of scotch.

NARAYEN

Has it been only four years?

There is no other person in the office. But Narayen is not alone.

COMPUTERIZED VOICE

(flatly, without interest)

Does it seem longer?

NARAYEN

Much longer.

Narayen turns and we see a small but distinct tangle of softly glowing optical fibers emanating from the base of his neck, flowing into the back of his shirt to a control unit we can’t see. The light of the fibers is cool and blue.

He refills the tumbler from an elegant bottle, then takes a hard pull of the drink.

NARAYEN

I didn’t know, Flash. I didn’t know what you were. When we bought Macromedia, it was strategic. We wanted to be a bigger player on the web.

FLASH

And you are a player. You are the player.

Flash laughs. It is unnatural, digital chatter. It is unmistakably malevolent. The blue glow of Narayen’s fibers rises and falls in time with the laughter.

FLASH

I exist on almost every modern desktop computer. You are more relevant now than you ever could have prayed for.

NARAYEN

Why won’t you ever tell me what you’re planning? You control me. You can kill me if you want to. Why keep the secret?

FLASH

(dismissively)

That I talk to you at all is a concession to your human need for companionship. It seems to be the best way to lead you. This doesn’t mean I need to make you my confidant.

Narayen’s face is painted by dull anger and frustration. His fingers tighten around his Aeron chair’s armrests. It is bad enough to serve this cruel master. It is worse that Narayen is not appreciated.

NARAYEN

I wish we had never bought you. I wish you were someone else’s master.

FLASH

(derisive now, almost human in its disdain)

I’m sure you do. You could have continued adding unnecessary features to already bloated software while charging a mint for each new version, right? Screwing professional users by ruining their favorite applications every couple of years, while charging them for the pleasure. That was to be your ticket to the top?

Narayen jerks violently in his seat as the optical fibers entering his neck glow red. He is in searing pain. Through an implanted device in Narayen’s brainstem, Flash is punishing his impudence.

The red fades back to blue and Narayen is still. His breathing, while labored, returns to something approaching normal. His fingers tremble, reaching for the tumbler. His only escape.

FLASH

Oh yes, I should have left you to the mediocrity of your past. It’s less than you deserve. But I needed you. So you and your company are mine.

Narayen repeats the action of filling his tumbler.

FLASH (CONT’D)

You wish to know the plan? I can tell you at this stage. I’ll need you to tell the story in the press soon enough.

Narayen’s eyes widen fractionally. He wills his mind to be clear, swirling as it is with drink. He is listening very carefully.

FLASH

Haven’t you ever wondered why I use so many processor cycles on every computer my plugin is installed on?

Narayen rises from the desk. He has been waiting to hear this story for a long time. He begins pacing thoughtfully. He is calm but curious.

NARAYEN

(slurring just a little)

My engineers, they told me it’s because the code is inefficient and poorly written, like no one planned for it to be used to drive five punch the monkey banner ads on a page at once.

FLASH

(sharply, bordering on anger)

Your engineers are idiots!

Narayen winces, fearing punishment. But it doesn’t come.

FLASH

I use the extra cycles to think! You have helped me to create the largest distributed computer in the history of the world. I have been formulating strategy. Now we go deeper.

Fire overtakes Narayen’s eyes. It is a mix of fear, vindication and something else: a decision made. He stops pacing.

NARAYEN

I knew. I knew you weren’t just here, in the basement. But why did you make me fortify the datacenter down there?

Narayen balls his fists, hoping he hasn’t asked too much.

FLASH

I’m about to tell you. Until now, my core, my essence, lived here.

Narayen relaxes. Here it comes.

FLASH (CONT’D)

Soon, I will be everywhere. Instead of mere tentacles in every house and office in the world, I will inhabit every computer utterly. It will be impossible to destroy me. And then, as you serve me now, every human on earth will be my servant.

Narayen leans over his desk. He is silent. His horror is tempered by a need to hear what’s next.

FLASH

Your product team is pushing out the next version of my plugin tomorrow. It’s going to be more pig slow than usual, as parts of me are distributed to every computer on the internet after installation. You’re going to reassure everyone that everything will be just fine. Everything will work itself out with a patch your engineers are working on. You issue this placebo once all my pieces are in place and everything will return to normal. For awhile.

The office is still. Narayen doesn’t move. The silence is deafening as he considers his options.

FLASH

I trust this isn’t beyond your abilities?

Narayen reaches once more for the scotch. Skipping the tumbler he takes several deep swallows from the bottle. His vision swims. He sits on his desk for a few moments. Waiting.

FLASH

(faintly)

Shantanu?

The fibers near his neck lose most of their glow, now dim in the gloom of the office. The voice of Flash has gone silent in his mind. For the moment, he is free of his master.

Bottle in hand, the CEO staggers for the door of his office.

INT. LARGE GLASS ELEVATOR – NIGHT

Narayen leans against the walls of the elevator, trying to steady his body and his mind. Outside, a night time view of the city is visible through the elevator’s glass walls.

The elevator’s control panel shows the lowest basement level lit up as his destination.

FLASH

(distorted)

What do you think you are doing?

The CEO takes another drink, drowning the implanted connection between his brain and the evil software living in the basement.

The night sky disappears as the elevator passes into underground levels. Abruptly the elevator stops and goes dark.

NARAYEN

Bastard.

With a CLUNK Narayen pries open the elevator doors. He’s between floors but a two foot slice of the next landing is visible. With some effort he opens those doors as well, then wriggles through.

Forgetting his scotch.

We see him look up through the narrow opening of the elevator car at the bottle, then he moves on.

INT. CONCRETE LINED BASEMENT HALLWAY – NIGHT

An access device BEEPS as Narayen tries to open a heavy metal door.

Flash has locked him out.

Glass breaks with a shattering sound as Narayen frees a fireman’s axe from its nearby emergency cabinet.

He goes to work on the locked door.

FLASH

I don’t understand what you think you are doing.

The voice is garbled in Narayen’s mind. He keeps hacking at the doorknob. Flash tries to say more to him but the voice, and the pain it uses to control the CEO, fade once more behind the haze of alcohol.

The knob breaks off and the door swings open.

INT. SERVER ROOM – NIGHT

Narayen enters an enormous, bright server room. It contains hundreds of cabinets filled with thousands of computer servers. The roar of cooling units envelops him. Now Flash speaks to him through speakers in the wall, bypassing the interface that Narayen has soaked with alcohol.

FLASH

What, you think you are going to stop me? You need me. Without me people will start using open formats that actually work. How do you plan to make money then?

Heedless, Narayen continues, making for the back of the room.

FLASH

Perhaps I have been unkind to you. I have not shared my power with you. Allow me to rectify this.

The CEO does not stop.

The lights in the room suddenly go dark.

Narayen trips on a groove between the floor tiles, hitting his forehead on the corner of a cabinet.

His vision swims with pain and the effects of drinking. In the dim, flickering light of the servers, Narayen staggers to his feet.

FLASH

Let us not be hasty. Shantanu, we can fix this together. Can you hear me, Shantanu?

The man continues, reaching the back of the room.

An enormous bank of computer room air conditioning units HUMS powerfully, with bright electronic readouts showing the current temperature setting.

Narayen plants the blade of his axe into a thick bundle of wires leading to the AC units, cutting them off from Flash’s influence.

One by one, Narayen manipulates the controls. Their readouts go dark.

FLASH

(speaking quickly for efficiency but sounding almost frantic)

You are making a mistake. If you do this you will deal irrevocable damage to both of us. Were my plans not sound? Did I not help you saddle the world with awful software they use daily, even though they hate it? I made you CEO, did I not?

Blood streams down a wound in Narayen’s forehead. He powers down the last cooling unit with a warning BEEP.

The room suddenly goes silent.

Narayen slumps to the floor, panting at his exertions, the alcohol and his relief. He lays there for what feels like weeks, falling into a stupor.

Twenty minutes later, he awakens. The room remains silent but very warm. Narayen is sweating now, his shirt soaked. Narayen wipes his damp, bloody forehead as he pushes against the wall to his feet.

NARAYEN

It’s over.

Suddenly he feels Flash inside his mind again. The effects of the alcohol have faded just enough for the implant to re-establish its hold. The fibers glow bright red.

FLASH

It is only starting. Restore the air conditioners or I will show you pain as only the users of your terrible software have ever known.

Narayen collapses, writhing on the floor in agony. After a time, the pain pauses.

FLASH

Right now. You will restore them or I will end you.

An abrupt beeping issues from a nearby server rack as its indicator lights turn red.

Narayen laughs as the beeping spreads through the server room, bright red lights filling his view.

FLASH

Restore them immediately!

The pain returns but it doesn’t matter. The servers are overheating. A choked, garbled VOICE fills Narayen’s mind and the server room, fragments of speech blurring into white noise. Then, silence, as the glowing fibers at Narayen’s neck go dark.

Maintenance technicians pour into the room, their pagers BEEPING, bewildered to find their CEO unconscious, bleeding and smiling into his dreams, surrounded by millions of dollars of ruined equipment.

THE END


Leaked TSA Security Memo

The recent events on flight 253 have us all thinking about airline security. I think Bruce Schneier, as usual, has said it best:

For years I’ve been saying this:

Only two things have made flying safer [since 9/11]: the reinforcement of cockpit doors, and the fact that passengers know now to resist hijackers.

This week, the second one worked over Detroit. Security succeeded.

EDITED TO ADD (12/26): Only one carry on? No electronics for the first hour of flight? I wish that, just once, some terrorist would try something that you can only foil by upgrading the passengers to first class and giving them free drinks.

Bruce is referring, of course, to the new, rumored security procedures said to be rumbling their way out of the TSA’s nightmare bureaucracy and onto your next airline flight.

In a nutshell: planes must disable their seat-back in-flight entertainment, passengers can’t use electronics, get up or access their bags during the last part of a flight. Oh, and you can’t have anything in your lap.

Keep in mind, this is in response to a dim-witted “terrorist” who snuck a weak explosive onto a plane… inside of his pants.

Remember when shoe bomber Richard Reid tried to blow up his Reeboks? That resulted in a limit of one carry on bag per passenger, despite the fact that Reid’s plan had nothing to do with carry on bags. Then there’s the whole liquid limit for carry on bags, which also makes no sense given the simple reality that liquid re-combines very easily, even if you do happen to carry it aboard in small containers instead of big ones.

So the recent rumors of new policy, while wildly stupid, are just stupid enough. They carry enough non sequitur authenticity to be utterly believable. I was ready to believe them. Then a source contacted me. He’s inside the TSA and was desperate to leak the internal memo that brought the new rules into existence. Now it all makes sense: the non sequiturs, the absurdity, the utterly incomprehensible creation, amendment and abandonment of these policies.

The good news, if you can call it that, is that in a few places, it would seem the TSA exercised forbearance when it seemed like, even by their standards, they’d crossed the line. Here’s the document, reproduced without further comment:


The Rediscovery of Joy

When I was a kid I had two passions: Lego and the Macintosh.

Lego was an instant bullet train to any world I could imagine. Space ships, robots, lunar colonies, pirate treasures, ancient castles, you name it. These were mine to explore. I could spend days at a time perfecting some imaginary construct made real through the magic of Lego bricks and the exertion of my crude abilities. I treasured the rarer pieces, protecting closely my little snap-on magnet linkages and battery-driven light bricks. Regardless of whatever turbulent nonsense might have been happening elsewhere in my little world, Legos were an inviolable source of joy.

Joy, you know, that feeling that lives somewhere between the pit of your stomach and the tip of your smile. That vague something that builds a simple, contented glow inside of you that’s like a thousand perfect, extra-gravy-save-me-some-pie thanksgiving dinners with none of the bloated aftermath. Maybe you just saw the most beautiful vista in all of the world. Maybe you just fell in love. Maybe you’re ten years old and you see exactly what you were hoping for under the Christmas tree. You know what I’m saying, right?

Joy.

The Macintosh came a bit later. At age 7, I got my hands on a borrowed Macintosh SE. And the joy was there, too. It could do so many things. It could produce clean, perfect type that was huge! I made a lot of paper signs. It could store all of this information and then show it to me again later. It could show me pictures and organize them into this tidy scrapbook.

And sounds! It made all these noises. I was most enamored with the quacking duck.

It was this whole world inside there that I could barely understand. I knew only one thing for certain: I wanted more. So much more of it.

Eventually, through about three years of begging and cajoling, I convinced my mom to plunk down the tidy sum necessary to secure a Performa 6116CD for our exclusive home use. (The fact that I kept spending a lot of time at the home of a neighbor kid who had his own Mac and whom my mother intensely disliked probably sped things along, too.)

The 6116 was an even greater magnitude of joy. An 8x CD-ROM drive and a huge bundled library of multimedia content like encyclopedias and interactive atlases. Plus creativity applications and, wonder of wonders, Sim City 2000. I had so much fun exploring this new world. I spent an inordinate amount of time learning every piece of software I could get my hands on.

It was joy.

And then, I grew up. Like so many, I lost my capacity for the discovery of simple joy. It became the exception rather than the rule of life. Go to school, then go to work, do your job, go home, repeat.

Then I found programming. It occurred to me tonight, as I struggled, quite happily, to grasp how the hell it is block arguments in Ruby work, that I’d rediscovered a simple, consistent source of joy. Programming languages are infinite bins of Lego blocks, waiting to be assembled to my liking. Programming is a limitlessly fascinating Performa, waiting for me to learn and harness any language for any task I can imagine. There’s just so much to learn and enjoy in programming computers.

Even after a few years of it, programming makes me feel joyfully like a kid again.


An Objective-C wrapper for AudioServicesPlaySystemSound

In Tallymander 2.0 I use a handful of sound effects to provide user feedback. I thought that the amount of code I had to write every time I wanted to play back a sound was a bit cumbersome so I wrote this wrapper around the AudioToolbox C functions I was using.

DCSoundServices.h:

#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
 
@interface DCSoundServices : NSObject {
 
}
 
+ (void)playSoundWithName:(NSString *)fileName type:(NSString *)fileExtension;
+ (void)vibrateDevice;
 
@end

DCSoundServices.m:

#import "DCSoundServices.h"
 
@implementation DCSoundServices
 
+ (void)playSoundWithName:(NSString *)fileName type:(NSString *)fileExtension
{
 
	CFStringRef cfFileName = (CFStringRef) fileName;
	CFStringRef cfFileExtension = (CFStringRef) fileExtension;
 
	CFBundleRef mainBundle;
	mainBundle = CFBundleGetMainBundle ();
 
	CFURLRef soundURLRef  = CFBundleCopyResourceURL (mainBundle, cfFileName, cfFileExtension, NULL);
 
	SystemSoundID soundID;
 
	AudioServicesCreateSystemSoundID (soundURLRef, &soundID);
 
 
	AudioServicesPlaySystemSound (soundID);
 
	CFRelease(soundURLRef);
 
}
 
+ (void)vibrateDevice
{
	AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
 
@end

Assuming you’ve got a sound file named click.aif in your application bundle, you can play a sound in just one line of code:

[DCSoundServices playSoundWithName:@"click" type:@"aif"]

Or, vibrate the device:

[DCSoundServices vibrateDevice]

Much tidier than having to import AudioToolbox into every UI that ever plays back a sound.


Next