AGK for Pascal
ContentsIndexHome
PreviousUpNext
5. Getting Started for iOS
Requirements
  • OS X 10.6 (Snow Leopard) or later.
  • Xcode 4.2 or later (available in Apple's App Store).
  • Free Pascal 2.5.1 or later for Mac OS X.
  • Free Pascal 2.5.1 or later for iOS.
  • iOS Framework Header Parser

 

You can download Free Pascal for Mac OS X/iOS here: 

http://sourceforge.net/projects/freepascal/files/Mac OS X/ 

Select the "2.5.1" folder (or later). You will find several .dmg files here. Download the files fpc-*.intel-macosx.dmg and fpc-*.arm-ios.dmg. Note: if you also use AGK for OS X development with Lazarus, then you have already downloaded and installed the fpc-*.intel-macosx.dmg package. 

The iOS Framework Header Parser can be downloaded here: 

http://web.me.com/macpgmr/ObjP/Xcode4/iOS_5_Parser_Input_Files.zip 

or, for the latest version, see this page: 

http://web.me.com/macpgmr/ObjP/Xcode4/iOS_5_Parsing_Status.html 

 

Installation
  • Install Xcode 4.2 or later. Note that Xcode 4.3 changed the way that Xcode is installed. In particular, there is no /Developer directory anymore and the command line tools are not installed by default anymore. Both of these are needed by Free Pascal. So these additional steps are needed if you use Xcode 4.3 or later:
    • Create an alias (symbolic link) /Developer to the /Developer folder inside the Xcode bundle. To do this, open a terminal window and enter this command:

      sudo ln -s /Applications/Xcode.app/Contents/Developer /

      (Note the space before the last slash).

    • You must have read and write access in the Developer folder. An easy way to give everyone read and write access is with this command:

      sudo chmod 777 /Applications/Xcode.app/Contents/Developer

    • Open Xcode and go to the "Xcode | Preferences..." menu option. Go to the "Downloads" tab and install the Command Line Tools.
  • Install AGK for Pascal in the directory /Developer/AgkPas. You may install it in a different directory, but the Xcode template assumes it is installed in this directory.
  • Open the downloaded fpc-*.intel-macosx.dmg file. It contains two packages (fpc*.pkg and fpc-xcode*.pkg). Install both packages.
  • Open the fpc-*.arm-ios.dmg file and install the package it contains. This one may take some time because it builds Free Pascal for the ARMv6, ARMv7 and iPhoneSim platforms.
  • Because of restrictions in Apple's licensing, Free Pascal doesn't ship with the iOS header translations. And because of these same restrictions, we can also not ship these with AGK for Pascal. The iOS Framework Header Parser provides a (legal) solution to this by parsing the iOS header files locally and converting them to Pascal sources:
    • Unzip the downloaded Header Parser ZIP file. By default, it is unzipped to the Downloads folder.
    • Open a terminal window and enter these commands:

      cd ~/Downloads/iOS_5_Parser_Input_Files

      (or the directory you unzipped to)

      sudo sh parse-ios.sh iphoneall

    • If the parser complains that it cannot find the iOS SDK, then you are probably using a newer SDK than officially supported by the parser. However, it may be possible to run the parser anyway by passing the path to the SDK. For example, Xcode 4.3 comes with the iOS 5.1 SDK, but the parser I used only supports up to version 5.0. So I ran the parser using this command:

      sudo sh parse-ios.sh iphoneall /Developer/Platforms/iPhoneOS.Platform/Developer/SDKs/iPhoneOS5.1.sdk

    • In Finder, go to the iOS_5_Parser_Input_Files/uikit_skel/src subdirectory.
    • Copy the contents of this directory to the folder /Developer/AgkPas/Source/iOS. There should be an iPhoneAll.pas file in that directory now.

 

Creating an AGK project

The easiest way to start a Lazarus AGK application is to use a template. The template can be found in the /Developer/AgkPas/Templates/iOS_Xcode directory. 

 

  1. Copy the files in the /Developer/AgkPas/Templates/iOS_Xcode directory to your application directory.
  2. Start Xcode.
  3. Open the copied project.
  4. You can rename the project in Xcode and make other customizations.
  5. Build and run the application for the iPhone simulator, iPad simulator or an actual iOS device.

 

After the AGK for Pascal launch screen, the text "Hello AGK for Pascal!" should appear. The application is designed for landscape mode, so you may get a better view if you rotate the (emulated) device. You can now modify the unit uMain and change the application settings and add your game code. 

Note: if compilation fails, then this is probably because you have not installed AGK for Pascal in the /Developer/AgkPas directory. In Xcode, open the project navigator and select the project. The open the "Build Settings" tab and scroll down to the User-Defines settings. You will find all Free Pascal related compiler settings here. Open the FPC_COMMON node to find 2 settings (for Debug and Release builds). Edit each of these settings. You will find various references to the /Developer/AgkPas directory. Change those the directory where you installed AGK for Pascal. 

Note: another possible reason for compilation failure is that your application, or the AGK for Pascal library, is installed in a directory with whitespace characters in its name. Free Pascal doesn't like that. 

For more information about using Xcode with Free Pascal, check out this site: 

http://web.me.com/macpgmr/ObjP/Xcode4/ 

 

Note about application resources

iOS applications expect that its resources (like images, sounds etc.) are packaged into the application bundle. To add these resources to the bundle, just add them to the Xcode project. I usually put the resources in a folder called Media in the Xcode project. If you are using the template, you will already find a Media folder there with a single agk.png file. You can add your own resources to this folder. 

 

Examples

If you want to check out some examples, then look at the Examples directory. It contains a large number of sample applications, categorized in various subdirectories. Each subdirectory contains an Xcode workspace with all the sample projects for that category.

Copyright (c) 2012. All rights reserved.