Open sesame

Here’s a simple little script that saves me a lot of time:

#!/bin/sh 

if [ -z "$1" ]; then
  echo "usage: $0  [ Preferences |  ]"
else
  base=~/Library/Application\ Support/iPhone\ Simulator/
  apps=Applications
  app=`ls -1td "$base/"*"/$apps/"*"/$1.app" | head -1`
  if [ -n "$app" ]; then
    dir=`dirname "$app"`
    if [ "$2" = "Preferences" ]; then
      open "$dir/Library/Preferences"
    else
      open "$dir/Documents/$2"
    fi
  fi
fi

Put this script somewhere on your PATH and name it opensim. Use it to find the most recent application loaded in the simulator and open the Preferences, Documents or a named document in the Finder.

For example, to open the current Documents folder for an application in the iPhone Simulator, just do this:

$ opensim Thunderbird

To open a document within that folder, you can do this:

$ opensim Thunderbird chockenberry.db
$ opensim Thunderbird accounts.plist

You can easily get to your preferences folder with:

$ opensim Thunderbird Preferences

Notice how I haven’t mentioned a GUID in this essay? That’s the feature…

Sharing iPhone projects

The latest version of Xcode has a “feature” that prevents you from specifying a wildcard name for the Code Signing Identity. (This feature does make it easier for new developers or people working alone, so I’m not going to write a Radar for this behavior.)

When you have multiple people working on an iPhone project, this behavior is very annoying because every developer has to change the Code Signing Identity before they can run the latest version on the device. Here’s a typical scenario:

  1. I set the Code Signing Identity to “iPhone Developer: Craig Hockenberry” and do my device build. Everything is wonderful and I check in a new SekretApp.xcodeproj/project.pbxproj.
  2. I add some cool new features to SekretApp and I want Anthony Piraino to try them out. Anthony updates his working copy to the latest version.
  3. Anthony has to change the Code Signing Identity to “iPhone Developer: Anthony Piraino” so that he can do the device build. He does, and everything is wonderful.
  4. Anthony then adds some new files to the project. He checks in a new SekretApp.xcodeproj/project.pbxproj as a result of this change.
  5. I need these new files, so I get the latest version of the project. Unfortunately, this latest version has Anthony’s Code Signing Identity in it. Everything is not wonderful.
  6. Lather, rinse, repeat.
It gets even more fun when you have merge conflicts. The solution to this problem is to get rid of the individual developer names in the project.pbxproj file.

Before you begin, make sure that you’ve closed the Xcode project you’re going to be updating. You are going to be modifying files used directly by Xcode, so things can get screwed up if you make changes while the project is alive.

The first step is to locate SekretApp.xcodeproj in the Finder and right click on the file. Select “Show Package Contents” to reveal the project.pbxproj file.

Now, open project.pbxproj with your favorite text editor and look for the Code Signing Identity. It will look something like this:

CODE_SIGN_IDENTITY = "iPhone Developer: Craig Hockenberry";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Craig Hockenberry";

Change the identity to look like this:

CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";

You also need to delete the embedded provisioning profiles. These are normally located a few lines below the CODE_SIGNING_IDENTITY:

PROVISIONING_PROFILE = "DEADBEEF-1337-FACE-F00D-EA7A7BADCAFE";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "DEADBEEF-1337-FACE-F00D-EA7A7BADCAFE";

(And, yes, I felt very lucky the day I was assigned that GUID.)

Note that there will probably be more than one CODE_SIGNING_IDENTITY (depending on your Project and Target settings.) Make sure to search through the whole file.

After making these changes, re-open the project in Xcode, clean it, and do a device build. If you make it through the CodeSign build phase, you’re good to go. Now all you have to do is check in the new version of project.pbxproj.

This trick works because the underlying codesign utility searches your keychain for a match. From the SIGNING IDENTITIES section of the manual page:

To be used for code signing, a digital identity must be stored in a key-chain that is on the calling user’s keychain search list. The identity is located by searching all such keychains for a certificate whose subject contains the identity string given. If there are multiple matches, the invocation fails and no signing is performed.

Since you and everyone else on your team has only one certificate with the pattern “iPhone Developer”, this search works correctly and no one will need to update the project settings after they check out the latest version of project.pbxproj.

And everything will stay fricken’ wonderful.

Bootstrap

A lot of people stumble upon this website because they’re looking for information about developing applications for the iPhone. If this is your first time here, welcome!

I have been developing applications for the iPhone since it was released (using both the Jailbreak and official SDK.) My company is currently selling several applications in iTunes. I also have many years of experience with the underlying technologies on the device (Cocoa, the predecessor to Cocoa Touch.) I’d like to share some of my experiences and give you some pointers that will help get you started.

The first thing you need to know is that learning how to develop applications for a mobile device isn’t easy. But it’s worth the effort, ask any seasoned iPhone developer about seeing their work run on the device for the first time: it’s fricken’ amazing.

Get a Feel for the Device

Some of you may want to target the web with your application. If this is the case, you’ll want to start looking at a series of articles I wrote for A List Apart: Put Your Content in My Pocket (Part 1 and Part 2.)

Even if you’re going to be writing a native application, knowing how to develop web pages for Mobile Safari will be helpful. A product information website and other ancillary information about your app will work best when your new customers can view it on their device.

Working with the web is also a good way to start understanding how a mobile device is so much different than a desktop. Using HTML and CSS can be an excellent way to begin thinking about your application design and doing prototypes—we’ve used this technique in many of our own products.

After getting a feel for the web capabilities of the iPhone and iPod touch, you’ll want to look around the Apple Developer Connection (ADC) site for more in-depth technical documentation for developing web applications.

Which leads to our next topic…

Buy a Mac

There’s no two ways about it. If you’re going to develop iPhone applications, you’re going to do it on a Mac. The whole toolchain is Mac-only: you can’t do it in Visual Studio or Eclipse or anything else that runs on Windows.

Don’t think that this is some evil plan by Apple to make you use a Mac. It’s no more nefarious than Microsoft requiring Mac developers to purchase Visual Studio in order to develop Windows versions of our products.

Buying a Mac can be an expensive proposition: if you’re just getting started and on a shoestring budget, here’s some advice on doing it on the cheap:

  1. Buy a used machine. A lot of perfectly good hardware can be found on Ebay. New models of the Mac Book Pro were recently introduced, so many people are selling hardware after they upgrade. This older hardware is perfectly fine for doing iPhone development: the apps you’re going to develop are small and compact and don’t need a lot of processor power to build and test.
  2. Buy a Mac mini. Even though you’re buying new hardware, you’ll save money because you’re supplying your own display, keyboard and other peripherals. If you’re like me, you have plenty of this stuff lying around.

If you’re having a hard time justifying the hardware expenditure, remember that you can run Windows or any other x86 based OS on this machine.

The only thing to keep in mind as you’re buying hardware: make sure that the Mac has an Intel processor. The development tools won’t run on the older PowerPC processors.

The good news is that once you buy the Mac, all the development tools are free. Think about all the money you spent buying Visual Studio and MSDN and you’ll feel much better about spending a thousand bucks for the hardware :-)

So how do you get all these free development tools? Read on…

Join Up and Download

There are two things you’ll need to do before you can start writing applications: sign up for ADC and register to become an iPhone developer.

Neither of these things costs money. Everything is free until you want to put your code onto the device. At that point, you’ll need to pay $99 to get a certificate that allows you to sign the binary and put it on the device.

The first step is to create an Apple ID; it’s an email address that you’ll use to access the developer site. You may already have one for your iTunes account. These pages guide you through the sign-up process.

Once you have an application that you want to test on a device and distribute on the App Store, you need to apply to the iPhone Developer Program.

After you have the keys to the ADC kingdom, there is a wealth of additional information available…

Sit Back and Watch Some Movies

Before you start diving into coding, I highly recommend spending a few hours watching the “Getting Started Videos” in the iPhone Dev Center.

(Note: if the links on that page are grayed out, it’s because you’re not logged in yet. Sign in using the Apple ID that you obtained above.)

As I said earlier, I came into iPhone development with a fairly extensive background in the technologies used on the device: even so, I learned a lot from these videos. Make sure you take advantage of this valuable resource.

And make sure you do it before rushing off and hacking on code…

Start Playing

If you’re like me, you’ll want to start playing around with code as soon as possible. The best way to do this is with the excellent sample code that Apple provides on its developer site.

(Note: Again, that link is behind a login, so you’ll need an Apple ID before you can download the samples.)

Since you’re new to iPhone development, it’s likely that you’ll have some problems going beyond a simple build and run of the projects you download. (If you’re having problems running the sample projects, make sure that you have “Simulator” selected in the drop-down menu at the top of the project window.)

When you start to get confused by Xcode or the syntax of Objective-C, you’ll want to move onto the next step…

(Note: I said “when”, not “if”. Trust me on this.)

Crack a Book or Two or Three

You’re lucky that there are a lot of great books about iPhone development available now. It’s a luxury that those of us who worked on iPhone apps during the NDA are very jealous of :-)

If you’re just starting out, I’d highly recommend Beginning iPhone Development: Exploring the iPhone SDK by Dave Mark and Jeff LaMarche. The best thing about this book is the step-by-step approach it takes to working with Xcode, Objective-C and the iPhone APIs. They’ll lead you through the basics and you’ll be building your own apps in no time at all.

As you get more comfortable with the tools and AppKit/UIKit frameworks, I’d recommend you take a look at Erica Sadun’s iPhone Developer’s Cookbook: Building Applications with the iPhone SDK. This book presumes a bit more knowledge about the SDK, but is a very handy reference both to the official and unofficial APIs. (Go ahead and play with the undocumented features, but do not use them in an application that you want to put on the App Store.) You may want to read my in-depth review of this book.

Since you’re going to be working with Cocoa Touch on the iPhone, you’ll also want to start thinking like a Cocoa programmer. Every great iPhone and Mac developer has nothing but wonderful things to say about Cocoa Programming for Mac OS X by Aaron Hillegass. Don’t be misled by the “for Mac OS X”—you’re going to be working with classes and design patterns that are identical on both platforms. You’ll also have a Mac that you’re using for development, so building the samples and test code isn’t a problem.

If you have previous development experience with C, C++ or Java, you’ll want to read this mailing list post by Erik Buck that enumerates some of the difficulties that you’ll have coming up to speed with Objective-C and Cocoa. Make sure to take some time and read the replies to that post: many of the people commenting on that post are fellow developers whose work I hold in high regard.

And while we’re talking about Erik’s writing: there are a lot of experienced Cocoa developers waiting for this book. You won’t need it for awhile, but you will need it.

As you’ve probably figured out by now, this whole learning process is going to take awhile. I’d also be remiss if I didn’t mention that there is a pretty steep learning curve. I’ve built products in assembly code, BASIC, C/C++ on Unix, X11, Win32, Java and a whole bunch of other technologies. Objective-C and Cocoa weren’t the easiest to pick up, but they’re definitely the ones that I plan on sticking with. Try not to get discouraged: once you “get it” developing with this language and framework is a joyous experience.

Other Resources

I’ve been coding long enough to remember a time when we didn’t have the Internet as a source of information. Thank God those days are behind us: here are some online resources that I use often:

  • cocoabuilder.com There are two mailing lists where other Cocoa developers and Apple engineers hang out: Cocoa-dev and MacOSX-dev. The archives for both of these lists can be searched using CocoaBuilder: extremely handy when you come up against a problem that someone else has already solved.
  • cocoadev.com A wiki that is maintained by the Cocoa developer community. This is the first place I look when I need to learn some new part of the framework. As an example, check out this entry about the string class.
  • cocoadevcentral.com A beautiful site maintained by Scott Stevenson. So many great tutorials and links to other sites and blogs that focus on Cocoa development. Spend some time exploring those links and you’ll learn a lot about our developer community.

Apple recently launched another great resource: Developer Forums. It’s currently in beta, but is still an excellent place to ask fellow developers questions about iPhone SDK topics.

But wait, there’s more!

You’ll find a lot of iPhone content on this site. Here’s proof.

To save you some time, here are some quick links to some of the more popular essays on this site:

Memory management issues (part 1.)

Memory management issues (part 2.)

How to run a beta test.

Extracting information from crash reports.

Final release testing.

What to expect on release day.

Debugging with customer backups.

How to deal with expired certificates.

And, of course, source code for you to use in your own projects:

[REDACTED]

Fancy UILabels

Or just have fun with:

Lights Off

And if you aren’t already completely bored with me crapping on about the iPhone, there are videos.

Conclusion

I hope this information has been helpful and gotten you started in the wonderful world of iPhone development. Don’t forget to subscribe to this site’s RSS feed since I have a lot more I’d like to write about :-)

Good luck!

Expiration perspiration

All hell broke loose for me in the Program Portal and Xcode today: welcome to 2009 and the expiration of development certificates over the holiday break. It’s far from obvious what is causing these problems, hence this quick essay to help others avoid them now and in the future. I’m sure that I’ll refer back to this essay on January 13th, 2010 when my latest certificates expire.

The problems began when I noticed that new devices couldn’t be added to an existing Ad Hoc provisioning profile. I assumed that meant something had changed in the Program Portal, so I wrote up a Radar ID# 6489692.

I then began looking for a workaround to the problem. When I tried to create a new distribution profile (using Program Portal > Provisioning > Distribution > Add Profile) I saw “Create a distribution certificate” instead of our company name. That led me to the root of the problem: our distribution and development certificates had expired.

A quick way to identify this problem is to open Keychain Access and do a search for “iPhone”. If you see a red X after “iPhone Distribution” or “iPhone Developer”, you have a lot of work to do.

Luckily, I had a copy of the original Certificate Signing Requests (CSRs) so recreating the certificates was straightforward. Words to the wise: keep a copy of your CSRs along with your private key developer key. If you’re not backing this stuff up in a safe place, you’re going to have some serious headaches in the future.

If you don’t have the original CSRs, you’ll need to follow the steps on the portal. Good luck.

Once I had approved the requests and the new certificate was issued, my Ad Hoc profile magically started working again on the Program Portal. Unfortunately, the magic didn’t extend to the development profiles. My developer certificate (“iPhone Developer: Craig Hockenberry”) had expired, but a reference to the previous one was still in the profile. To workaround this problem, I clicked on Edit > Modify on the Program Portal > Provisioning > Development page. On that page I added a checkbox to the second instance of my name (representing the developer certificate.) Once that was done, I generated new provisioning profiles.

As we all know, that’s only the beginning. To make Xcode happy, I removed the expired certificates from Keychain Access and downloaded new copies from the portal. Make sure to clear the search field, if don’t you’ll get confused because the search doesn’t refresh after the new certificate is loaded.

I then downloaded the new provisioning profiles and moved them into Home > Library > MobileDevice > Provisioning Profiles. After doing this, you need to quit and restart Xcode. Open your project file, select Project > Edit Project Settings from the menu bar and update the Code Signing Identity settings for each build configuration. Then say a little prayer and do a build. If there is a God, you’ll have a new signed binary.

To those Apple employees that are reading this, here’s a suggestion: send an email to a developer whose certificates are about to expire. The current system requires the developer to dig around a complex system to figure out what is broken. Since this system is designed to break over time (through expiration) please let us know it’s about to happen. It will make things easier for everyone involved.

Updated January 13th, 2009: You will also need to recreate the App Store provisioning profile for “iPhone Distribution”. Since it’s tied to the same distribution certificate that your Ad Hoc profile is, you’ll see “<matching certificate identity with private key not found in login keychain>” displayed when you try to select the Code Signing Identity in your Project Settings. Again, the portal is very awkward here: I needed to do the Edit > Modify > Submit with no changes to force the creation of a new .mobileprovision file. Once downloaded and installed in Library > MobileDevice > Provisioning Profiles, Xcode populated the signing identity list correctly.

Ringtone apps

Dear Steve,

As an iPhone developer who’s been in the App Store since its launch, I’m starting to see a trend that concerns me: developers are lowering prices to the lowest possible level in order to get favorable placement in iTunes. This proliferation of 99¢ “ringtone apps” is affecting our product development.

Unlike a lot of other developers, I’m not going to give you suggestions on what to do about this: you and your team are perfectly capable of dealing with it on your own terms. Rather, I’d like to give you some insight into how these ringtone apps are affecting my business.

Both of our products, Frenzic and Twitterrific, have been quite successful in the App Store. Frenzic is currently in What’s Hot and Twitterrific appears in both the Top Free and Top Paid Apps for 2008. We also won an ADA at this year’s WWDC. It hasn’t been easy, but we’ve learned what it takes to make a kick ass product for the iPhone.

The problem now is funding those products.

We have a lot of great ideas for iPhone applications. Unfortunately, we’re not working on the cooler (and more complex) ideas. Instead, we’re working on 99¢ titles that have a limited lifespan and broad appeal. Market conditions make ringtone apps most appealing.

Before commencing any new iPhone development, we look at the numbers and evaluate the risk of recouping our investment on a new project. Both developers and designers cost somewhere between $150-200 per hour. For a three man month project, let’s say that’s about $80K in development costs. To break even, we have to sell over 115K units. Not impossible with a good concept and few of weeks of prominent placement in iTunes.

But what happens when we start talking about bigger projects: something that takes 6 or even 9 man months? That’s either $150K or $225K in development costs with a break even at 215K or 322K units. Unless you have a white hot title, selling 10-15K units a day for a few weeks isn’t going to happen. There’s too much risk.

Raising your price to help cover these costs makes it hard to get to the top of the charts. (You’re competing against a lot of other titles in the lower price tier.) You also have to come to terms with the fact that you’re only going to be featured for a short time, so you have to make the bulk of your revenue during this period.

This is why we’re going for simple and cheap instead of complex and expensive. Not our preferred choice, but the one that’s fiscally responsible.

I’m also concerned that this “making it up in volume” approach won’t last too much longer. With 10,000 apps in the App Store, it’s already a fricken’ cat fight to get into one of the top 100 spots. What’s it going to be like when there are 20,000 apps? Or 100,000 apps? Volume is going to get split amongst a lot of players, hopefully the number of devices/customers will increase at the same rate.

We’re not afraid of competition. In fact, we welcome it as a way to improve our products and business. The thing we’re hoping for is a way to rise above the competition when we do our job well, not just when we have the lowest price.

I’ve been thinking about what’s causing this rush to the 99¢ price point. From what I can tell, it’s because people are buying our products sight unseen. I see customers complaining about how “expensive” a $4.99 app is and that it should cost less. (Do they do the same thing when they walk into Starbucks?) The only justification I can find for these attitudes is that you only have a screenshot to evaluate the quality of a product. A buck is easy to waste on an app that looks great in iTunes but works poorly once you install it.

Our products are a joy to use: as you well know, customers are willing to pay a premium for a quality products. This quality comes at a cost—which we’re willing to incur. The issue is then getting people to see that our $2.99 product really is worth three times the price of a 99¢ piece of crapware.

I also worry that this low price point for applications is going to limit innovation on the platform. Sure, apps like Ocarina and Koi Pond are very cool and very cheap. But when are we going to see the utility of the platform taken to another level, like when spreadsheets appeared on the Apple ][ and desktop publishing appeared on the Mac? (It could be argued that Safari has already accomplished this, but I still think there is a third party idea that will be just as transformative.)

It would be great if the killer app for the iPhone cost 99¢, but given the numbers above I can’t see it being very likely.

Thanks for your time and attention. I hope this information has been helpful.

Best regards,

Craig Hockenberry

Updated December 12th, 2008: David Barnard shares some numbers and experiences from selling his App Cubby products. Of particular interest are the difficulties in measuring the effectiveness of our marketing efforts. With no feedback other than raw sales, it’s hard to know if your advertising dollars are well spent.

Updated December 23rd, 2008: It looks like this is going to be the first thing new iPhone and iPod touch owners are going to see on Christmas morning. You and your team have worked so hard to make a device with such great potential: why is this happening?