iPhone/iPod development

From Lazarus wiki
Revision as of 22:52, 11 January 2009 by Skalogryyz (talk | contribs) (New page: The first version of FPC for the iPhone SDK 2.x is available. === Installation === Note that unlike other FPC releases, this installer will install the FPC sources (of FPC 2.3.1, svn re...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The first version of FPC for the iPhone SDK 2.x is available.

Installation

Note that unlike other FPC releases, this installer will install the FPC sources (of FPC 2.3.1, svn revision 12530 of today) and a script, and will then launch this script in order to compile FPC (after you tell it where you installed the iPhone SDK, so it can generate a Pascal version of some required C headers). This modus operandi is necessary to comply with the iPhone SDK agreement's stipulation that no derived works of the SDK may be distributed.

Requirements:

  • Intel Mac (because the iPhone SDK requires an Intel Mac)
  • iPhone SDK 2.x installed (only tested with 2.2 though) (note: SDK requires Leopard 10.5.5 or higher)
  • FPC 2.2.2 or a later FPC 2.2.x release installed

Some features:

  • Simulator support (it turned out to be trivial to add)
  • the Xcode template transparently supports (requires, actually) integrating Pascal and Objective-C source files into a single application
  • Pascal translation of the OpenGL ES 1.1 C-header from the SDK (this one I can distribute, because it's licensed under an SGI open source license), available in the gles11 unit

Please read the entire ReadMe.rtf on the installer disk image before asking for help. It contains quite a bit of information on things to watch out for (especially when using the Simulator), and how to change the included template when adding extra Pascal source files.

The installer disk image is available here (17MB -- there are also advantages to only distributing the source): ftp://ftp.freepascal.org/fpc/snapshot/v23/arm-macosx/fpc-2.3.1v1.arm-iphone.dmg

If you encounter problems with the script that is launched when the installer finishes the installation, please always provide the entire contents of the Terminal window in which the script was executed when asking for help.

Apple's Licencse limitations

Developing applications for iPhone/iPod

FPC cannot work around the requirement of having an Apple-issued certificate to run self-written programs on an iPhone/iPod Touch. So you have to sign up to Apple's iPhone Developer program ($99/year) to run FPC-compiled programs on the real hardware (just like for regular Xcode-compiled programs).

Without such a certificate, you can only run programs on the simulator (possibly unless you have a jailbroken iPhone/iPod Touch, but in that case you are on your own;

Seek more about Apple's iPhone development program here: http://developer.apple.com/iphone/program/

Pascal headers required for developing

It is against the iPhone SDK agreement to distribute derivative works, and this is includes Pascal translations of framework headers. So it would be quite a challenge (if possible at all) to create and distribute the sources of a complete Pascal program with a GUI that does not violate the iPhone SDK agreement terms at this time. See the ReadMe.rtf (provided at .dmg above) file for more information

Technical Development Limitations

For now, it is impossible at this time, because now way known, other than XCode, to copy an application to the iPhone/iPod Touch and to execute it. It's possible to develop the application using any IDE available (Lazarus, Lightweight IDE, etc) as well as it should be possible to make any of it to work with the Simulator. But still, any application should be build by XCode to upload the program to the Device.

iPhone Simulator is not iPhone

It does not make sense much to run programs in the Simulator, because the Simulator allows full access to the real Mac OS X, so you have no idea whether you are testing Mac OS X/iPhone-specific code or regular Mac OS X/i386 code. It's probably safer (and definitely much easier) to run them under plain Mac OS X/i386 in that case.).

That said, I've usually just compiled test programs on the command line (for ARM), and then copied them over the built binary in an Xcode project. If you then "run" the program in Xcode, it will code sign and run the binary that you copied over rather than the original program :) (just make sure that the binary in Xcode has been compiled recently so there are no changes that trigger Xcode to relink it).

You can find the binary's location by opening the "products" folder in the project overview, right-clicking on the .app file and selecting "Reveal in Finder". The binary's location is then in program.app/Contents/MacOS. Just overwrite whatever file is there with the program you compiled.

To compile on the command line (replace "iphone2.1" with the directory in which you installed the SDK): ppcarm -FD/iphone2.1/Platforms/iPhoneOS.platform/Developer/usr/bin -XR/iphone2.1/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk tt2

To compile for the simulator, replace "ppcarm" with "/usr/local/lib/fpc/2.3.1/ppc386", and the -XR parameter with the path to a simulator SDK. And in case you created an alternate fpc.cfg that uses a different unit search path than /usr/local/lib/fpc/2.3.1/units/*, also add -Fu/usr/local/lib/fpc/2.3.1/units/*


You can also directly compile from Xcode, if you want: just create a new project based on the template, remove all files except for the *Prefix.pch, Info.plist, Framewoeks and Products from the project, and then add the test program file (Project->Add to Project...). Finally, double click on the project icon at the top left in the file list, go to the Build tab, and change the FPC_MAIN_FILE setting to the name of the test program you added (for all configurations). Then you can build it.

To see the console output of the test programs, press cmd-shift-r (or select Run->Console)