Developing with Objective Pascal

Part 4: iOS Devices and Xcode 4


Contents

Introduction
Requirements
Compiling Pascal iOS headers for ARM
Obtaining a provisioning profile for your app
Running your app on an iOS device
Reviewing the build log
Next steps


Introduction

These notes describe how to compile an Objective Pascal Cocoa Touch app with the Free Pascal ARM cross-compiler and run the app on an actual iOS device. You should already have installed Xcode 4 and reviewed Part 1, Part 2 and Part 3.


Requirements


Compiling Pascal iOS headers for ARM

In Part 3, you parsed the iOS headers to create the source for the iPhoneAll unit and compiled the unit for use with the iOS Simulator compiler. Now you need to compile it for use with the ARM cross-compiler.

  1. Change to the folder where the iPhoneAll source files are located. For example:

    cd /Developer/ObjectivePascal/utils/uikit-skel/src
    
  2. Now compile the iPhoneAll unit:

    ./compile-arm.sh iPhoneAll
    
    Using the script included with the header parser ensures that the compiled object (.o) files contain both armv6 and armv7 code.

  3. Copy the compiled files to where your project will look for them.

    The Cocoa Touch template assumes that the compiled iPhoneAll files for ARM are in the following location, although you can place them wherever you want and just edit the path in your project settings:

    /Developer/ObjectivePascal/units/arm-darwin
    
    Here are the files you need to copy:

    iPhoneAll.o
    iPhoneAll.ppu
    AnonClassDefinitionsUikit.o
    AnonClassDefinitionsUikit.ppu
    

Obtaining a provisioning profile for your app

Creating a provisioning profile may seem confusing at first, but all you're doing is tying together three things: a developer, a device and an app. Requiring a provisioning profile helps protect the user from malware and helps protect you from getting ripped off by software pirates.

Tip: The following steps describe how to manually create and download a profile. For many apps you can also let Xcode do automatic provisioning. For more information, see Apple's docs.

  1. Log into the iOS Dev Center. Note you must be a iOS Dev Center member to log in.

    http://developer.apple.com/devcenter/ios/index.action
    
  2. Click the iOS Provisioning Portal link.

  3. If you haven't done this previously for yourself, obtain an iOS Development Certificate.

  4. If you haven't done this previously for your iOS device, obtain a Device ID.

  5. Create an App ID for your app.

  6. Create a new Provisioning Profile.

  7. Download the provisioning profile.

  8. You can now log out of the iOS Dev Center.


Running your app on an iOS device

  1. Open your project in Xcode.

  2. If you manually created a profile, drag and drop the downloaded provision file onto Xcode's icon on the Dock. This will bring up Xcode's Organizer, where you should see the provisioning profile listed.

  3. In Xcode, check the ARCHS setting on the target's Build Settings tab to make sure you're compiling for the desired architecture(s). By default the template sets ARCHS to armv6. If you're targeting iOS 5 or later, change ARCHS to armv7 since all devices running iOS 5 can run armv7 code. You can also set ARCHS to armv7 armv6 to include code for both architectures in the same "universal" binary.

  4. Connect your iOS device to your Mac and unlock it by entering the device's access code.

  5. In Xcode, select your device from the Scheme list, then choose Product | Build to make sure Xcode can compile your app with the FPC ARM cross-compiler.

    Note: If you only see the generic iOS Device in the Scheme list, this probably means there's a mismatch somewhere. For example, make sure your device's version of iOS is equal to or greater than your project's deployment target.

  6. Choose Product | Clean, then Product | Run. Xcode will now build and copy the app to your device and run it. The screenshot below shows what it should look like on an iPhone or iPod touch.

   Figure 4-1. Screenshot of Part 3's example app on an iPod touch.


Reviewing the build log

This illustration shows a typical build log for the example app given in Part 3. Discussion follows below.

   Figure 4-2. The Xcode 4 build log for an Objective Pascal iOS app.

Here are some notes about several of the build steps shown in the log.


Next steps

These four articles introduced quite a bit of material for two different platforms (OS X and iOS) and three Pascal compilers (ppc386, ppcx64, ppcarm). There's still a lot more to cover, but that's for future installments.


Copyright 2011 by Phil Hess.

macpgmr (at) fastermac (dot) net

First posted May 1, 2011; last edited Feb. 25, 2013.