openFrameworks on iPhone

I spent today trying to get an openFrameworks app running on my iPhone, and now that I’ve gone through the headache, you don’t have to!  Getting the app running is the easy part.  Dealing with the provisioning and certificates and all of that shit ended up taking the most time.
I wrote this out kind of quickly after the whole process was done, so I am not 100% sure that everything is accurate, so if you have any trouble or something is unclear, please just leave a comment and I will fix it ASAP.

  1. The first thing you have to do is get an account at the Apple Developers Connection and buy a membership in the iPhone Developers Program.  The membership is $100 to put your apps on 100 phones.
  2. Once you’ve done that, you can download the most recent iPhone SDK.  I have been working with 3.0
  3. Install the SDK
  4. I have simplified the next few steps by offering a bundle of files that I have collected from different places.  So if you want to skip them, just download my openFrameworks-iPhone package here and unzip it.  Giving credit where credit is due – it includes stuff from, the ofxmsaof GoogleCode project, the iphone-glu GoogleCode project, and some compiled libraries from zach-gage’s ofiPhone package that he posted in this thread.  If you want to get all of that yourself, follow the sub-steps below
    1. Crack open a terminal and run the following commands.

      mkdir openFrameworks-iPhone
      cd openFrameworks-iPhone
      mkdir apps
      mkdir libs
      mkdir addons
      svn co apps/examples
      svn co libs/openFrameworks
      svn co addons
      svn co addons/ofxiPhone
      mkdir apps/iPhone
      mv addons/ofxiPhone/examples/* apps/iPhone
    2. Download these libs:
    3. Unzip them and put them in your ‘libs’ folder
  5. Now you should be ready to run an app in the iPhone simulator. Open up one of the example apps (examples/iPhone/iPhone Graphics Example/iPhone Graphics Example.xcodeproj) and try it out.
  6. Duplicate one of the iPhone examples and make your app.
  7. Okay, not the annoying part starts.  Go to the iPhone Developer Portal Program.  Since apple wants to control everything, this is like your base of operations for creating the stuff that you need to get your app on your phone.  There are 4 things you have to do in here.
    1. Generate a certificate (you’ll have to be signed in to see these links, but they are good instructions, so I’m not going to repeat them)
    2. Register your iPhone
    3. Generate an App ID for your app
    4. Let’s recap.  Your certificate identifies who you are.  You registered your phone so that Apple knows which phone is yours.  Then you made an App ID so Apple knows which app you want to use.  So the last thing you have to do is put all of those things together in something called a Provisioning Profile.  So follow these directions to make one of those.
  8. When you are all done with all of this stuff, you should be able to download a file from the Provisioning section called Your_Name.mobileprovision. This is the goal of all of the previous steps. If you have this file, you are ready to move on.
  9. Plug in your iPhone with the USB cable.
  10. open up XCode and go to Window > Organizer  You should see your iPhone in the list.  I think you need to activate it somehow to use for development, but I can’t quite remember.  It should be obvious.
  11. Drag this file onto the “Organizer” window and you should see something like this:picture-11
  12. Now go back to XCode, expand the “Targets” item in the left menubar, and double click on “iPhone”.  Click on “Properties”, and in the “Identifier” field, put the App ID string that you generated in step 11.3  It should look something like:
  13. In the same screen, click on “Build”, go to the Code Signing section, and under “Code Signing Identity”, select “Any iPhone OS Device” on the left, and “iPhone Developer: Your Name” on the right.
  14. You should now be able to build your app.  And when it builds, if your iPhone is connected, it will automatically get transferred to your phone.

Congratulations!  You should now have the app on your phone.

One more tip:  I haven’t tried this out yet, but when I realized that the iPhone simulator didn’t have accelerometer support, I googled around a bit and found this accelerometer-simulator project.  This could be very handy when testing apps that use the accelerometer.  It will save you the trouble of having to transfer your app to your phone every time you want to test the accelerometer.