Source Code and Packages

| | Comments (0) | TrackBacks (0)
Source Code
    When you start programming your first original program, you'll probably want to reuse the "main.m" source file that you find in another program (e.g. HelloWorld).   Just edit it and make sure it is importing your program's header.  And of course make sure it is specifying your program's name in the call to UIApplicationMain.  This should be self explanatory when you actually see it.
    So let's say you are creating a program called "Big Gulp".  Here is the layout of files I recommend:
  • main.m (a very small file...)
  • BigGulp.m (your primary application class...of type UIApplication)
  • BigGulp.h (the header file for your application class)
  • Makefile (the make file...recycle this from another program...be sure to edit it to make sure the filenames match your program)
Building Your Program
    When you want to compile and link your program, you will want to use a Makefile.  I'm no expert on this subject, and how they work is still somewhat of a mystery to me, but I do know that you it's best to copy the Makefile from another iPhone program you find and edit it to make sure it fits your program.  Be very careful...the file is very picky about white space (tabs, etc).  The Makefile easily deserves its own article, and so I won't go into too much detail here, but for now, you should be able to look at one and see what needs replacing.
    To compile, go to the prompt in your program's directory (e.g. Cygwin for Windows users).  If the Makefile is set up properly, the command "make clean" should delete any previously compiled binaries and give you a fresh plate...so go ahead and type that.  Then follow that by typing "make".  If it builds correctly, it should produce an executable file (whose name you specified in the Makefile).  Unlike Windows executables, this file will not have a special extension (.exe).  Or any extension, for that matter.  It will simply be plain extensionless file.

Package structure
    When you want get your program ready for installing on the iPhone springboard, you should create a directory on your computer called BigGulp.app (replacing "BigGulp" with the name of your app). 
    This folder should eventually contain the following files:
  • biggulp (or whatever your executable is called)
  • icon.png (the icon for your program)
  • Default.png (the splash screen for your program...should be 320 x 460)
  • PkgInfo (get this from another program and don't change it)
  • Info.plist (get this from another program but DO change it...)
  • (any other graphics file, etc. that your app needs)
Info.plist
    This is another file that you should borrow from some other iPhone program.  You will need to edit however.
    Specifically, you should edit the strings that come after the following labels (keys):
  • CFBundleExecutable - this should specify your app's executable file (e.g. biggulp)
  • CFBundleIdentifier - this should be some unique string...one that no other app in the world will have.  You may notice that it frequently looks like a web address in reverse.  This is merely a convention of coming up a unique identifier...since only one entity (company) will "own" a website name, two different companies won't accidentally use the same identifier.  Note that there is no requirement that this name have anything to do with a website, or that a website exists.  One place this identifier will be used is when you save user defaults, the iPhone will create a file by that name in the Preferences directory.
  • CFBundleVersion - this is whatever arbitrary version you have assigned to your app.
You should leave the other stuff alone, including the CFBundleInfoDictionaryVersion. 


Installing the app
    To install the app on your iPhone, you will simply need to copy the .app directory you just made into the /Applications directory on your phone (via SSH).  Make sure that both your app's directory (e.g. BigGulp.app) and the executable file inside it have full Execution permissions.  This is done by either your SSH program or by using an app like MobileFinder.
    After doing this, you will need to "respring" the phone...that is, restart SpringBoard.  There are a couple of apps that can do this for you, including SysInfo (from Robota Software - available on Installer).  Or you can simply reboot your phone (so it starts up again, showing the silver apple).  Your app should show up on the springboard.



0 TrackBacks

Listed below are links to blogs that reference this entry: Source Code and Packages.

TrackBack URL for this entry: http://mauvilasoftware.com/cgi-bin/mt/mt-tb.cgi/9

Leave a comment

About this Entry

This page contains a single entry by JLA published on January 27, 2008 12:17 AM.

Getting started (on Windows) was the previous entry in this blog.

Settings/Preferences : a Picture Essay is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Categories

Pages

Powered by Movable Type 4.1-en-release-26-r1120-20071224