How to create iOS applications with Adobe AIR

On 9th September Apple revoked the restrictions for technologies that are allowed to be used for creating iPhoneOs (iOS) applications. This means that you can use Flash, Unity3D, Titanium Developer or any other tools to make an mobile application for Apple devices.
As a result of this decision Adobe will resume work on Packager for iPhone which has been on hold since April this year (as a result of sections 3 of iOS Developer Program license).

Latest version of the packager has been released on 11th October, so let’s give it a try.
This approach for developing iPhone / iPad / iPod applications is a great way to reuse you ActionScript code but there are some Flash features that are not available or are known not to work properly – see ‘Known Issues’ section and ‘Packager for iPhone developer guide’ on Adobe Labs to be aware of those limitations.

There are two ways of creating native iOS applications with Adobe Flash platform:

  • using Adobe Flash CS5
  • using Packager for iPhone from the command line

Create iPhone / iPod / iPad application – step by step

1. Download ‘Packager for iPhone’ (PFI). Flex SDK is also required.

2. PFI requires 32-bit Java runtime environment, be sure to have it installed.

3. Create and Adobe Air project using ActionScript, not MXML.

In FlashDevelop create  ‘AIR AS3 Projector’ project.
In Flash Builder create ‘Flex Project’, but set the main application extension to ‘.as’.

4. Modify the Adobe Air application descriptor xml.

It should look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/2.0">
 
	<id>com.flashsimulations.mobile.ios.Hello</id>
	<version>1.0</version>
	<filename>HelloIOS</filename>
	<name>Hello iOS</name>
	<description>Just a test</description>
	<copyright>Piotr Koscierzynski</copyright>
 
	<initialWindow>
		<title>Hello iOS</title>
		<content>HelloIOS.swf</content>
		<systemChrome>standard</systemChrome>
<transparent>false</transparent>
		<visible>true</visible>
		<minimizable>true</minimizable>
		<autoOrients>true</autoOrients>
		<resizable>true</resizable>
		<renderMode>gpu</renderMode>
		<fullScreen>true</fullScreen>
		<aspectRatio>portrait</aspectRatio>
	</initialWindow>
 
	<supportedProfiles>mobileDevice desktop</supportedProfiles>
 
	<iPhone>
		<infoAdditions>
		<![CDATA[
			<key>UIStatusBarStyle</key>
			<string>UIStatusBarStyleBlackOpaque</string>
			<key>UIRequiresPersistentWiFi</key>
			<string>NO</string>
			<key>UIDeviceFamily</key>
			<array>
			<string>1</string>
			<string>2</string>
			</array>
		]]>
		</infoAdditions>
	</iPhone>
 
</application>

The descriptor is almost the same as the one for Android apps, but there are some differences

  • iOS apps must use Air 2.0 (line 1), Android uses Air 2.5
  • iOS apps use <version> not <versionNumber> for specifying version of application. But value should be in the same format – numbers only XX.XX.XX or XX.XX
  • the information for operating system is defined between <iPhone> tag. This may look new, but those parameters are the same that can be found in Info.plist file when developing iOS apps in XCode. For full list of available options visit Information Property List Key Reference for UIKit e.g. UIDeviceFamily defines on which devices the application can run – 1 is for iPhone / iPod, 2 is for iPad.

5. Register in iPhone Developer Program. Get a certificate and provisioning profile from Apple ($99-$300 per year). You also need to convert the
certificate into a P12 certificate. See the “Obtaining developer files from Apple” section, page 4 of ‘Packager for iPhone developer guide’. This process could take few days or even a week (Apple needs to verify information you provided) and can be complicated.

There is a second – ‘non-Apple’ – way. Well, you don’t really need to buy anything, but you won’t be able to submit your application to AppStore and you won’t be able to test on the ‘non-jailbroken’ iOS device. All you have to do is to find a ‘special’ certificate ‘.p12′ and ‘.mobileprovision’ files – Google will help you. Use those files to pack your application.

6. Configure and run the packaging batch ‘Package_iOS_Application.bat’ (if on Windows) or run the packager from the command line using this syntax:
pfi -package -target [ipa-test ipa-debug ipa-app-store ipa-ad-hoc] -provisioning-profile PROFILE_PATH SIGNING_OPTIONS TARGET_IPA_FILE APP_DESCRIPTOR SOURCE_FILES

7. Install you application on the device / submit to AppStore.

Adobe Air into native iOS – How does it work

The packager creates an native iOS application – it’s not Adobe Air application, because Apple forbids Just-In-Time compilation on their devices – that means no ActionScript Virtual Machine available – you won’t be able to run ActionScript code from external .swf files. Packager uses the LLVM compiler to translate ActionScript into Objective-C bytecode, it’s the same technology that’s behind Adobe Alchemy.

Example project

This project is exactly the same as my ‘Hello World’ example for Android. The project’s file structure looks like this

Hello iOS project structure

Packaging batch file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@echo off
 
:: iPhone application packaging script - based on FlashDevelop's AIR AS3 template.
:: Modified by Piotr Koscierzynski, flashsimulations.com
 
:: Flex SDK path
set PATH=%PATH%;"C:\Program Files (x86)\FlashDevelop\Tools\flexsdk\bin"
 
:: Directory containing 'Packager for iPhone', version released on 11th October 2010
set PFI_DIR="G:\piotr\SDK\packagerforiphone_v2_win_101110"
 
:: Packager for iPhone requires 32-bit Java runtime. The run parameters taken from PFI .bat file.
set JAVA_32BIT_RUNTIME_PATH="C:\Program Files (x86)\Java\jre6\bin\java" -Xms256m -Xmx1024m
 
:: You should use a valid certificate from Apple Developer Program.
:: You can also generate it by yourself - (see 'CreateCertificate.bat').
:: Certificate file path
set CERTIFICATE=pkoscierzynski.p12
 
:: Provisioning Profile from Apple Developer Program, required.
set MOBILE_PROVISION_FILE=pkoscierzynski.mobileprovision
 
:: Certificate and provisioning profile part
set SIGNING_OPTIONS=-provisioning-profile %MOBILE_PROVISION_FILE% -storetype pkcs12 -keystore %CERTIFICATE%
 
if not exist %CERTIFICATE% goto certificate
 
:: ---- Output ------------
if not exist ipa md ipa
 
:: iPhone IPA file
set IPA_FILE="ipa/HelloIOS.ipa"
:: IPA target type
set IPA_TARGET_TYPE=ipa-test
 
:: --- Input -----------
:: Application descriptor
set APP_XML="Hello-iOS-app.xml"
 
:: Application main swf
set FILE_OR_DIR=-C bin HelloIOS.swf
 
echo Packaging iPhone application using certificate %CERTIFICATE%
echo This process will take a few minutes. Please wait...
 
:: Package command
call %JAVA_32BIT_RUNTIME_PATH% -jar %PFI_DIR%\lib\pfi.jar -package -target %IPA_TARGET_TYPE% %SIGNING_OPTIONS% %IPA_FILE% %APP_XML% %FILE_OR_DIR%
 
if errorlevel 1 goto failed
 
echo.
echo SUCCESS! iPhone IPA installer created: %IPA_FILE%
echo.
goto end
 
:certificate
echo Certificate not found: %CERTIFICATE%
echo.
echo Troubleshotting:
echo A certificate is required, generate one using 'CreateCertificate.bat'
echo.
goto end
 
:failed
echo iPhone packaging FAILED.
echo.
echo Troubleshotting:
echo Please check Flex SDK and PFI path in this Batch file.
echo.
 
:end
pause

13 thoughts on “How to create iOS applications with Adobe AIR

  1. Hello,

    At the beginning congratulation for your website.

    i try to use mx.controls for a flex iphone project and it doesn’t work. It’s normal?

    (Sorry for my english, i’m frensh ;-) )

  2. Hi Julien, it´s normal, because for mobile development, you only can use spark.* components and controls, check that in Adobe website.
    Only a few controls (like charts) its allowed to be used on mobile devices ;)
    Enjoy

  3. Hi, I’ tried with sparks components but when I install the app in the iPhone meaning of components appears.

    I dont’ understand why.

    Thanks

  4. Hi,

    You can use both Halo and Spark components and your application will work, but you will face performance problems.
    I created an Flex 3 ‘Hello World’ with mx.controls.Alert and it takes about 2 seconds from ‘click’ event for the popup to show up, not very impressive. What’s more the application takes quite some time to load on my iPhone 2G.
    I’ll update this post with this example in the next few days.

    Also, Packager for iPhone requires AIR 2.0 namespace, so check whether you have that parameter set up correctly.

    The new mobile Flex framework ‘Hero’ requires AIR 2.5, so it’s not possible to leverage it to create iPhone applications with current version of PFI.

  5. Thanks for the informative post.

    Maybe you can help me understand some things I haven’t been able to figure out yet…

    Can an existing AS3 Flashbuilder project be exported as an iOS app, or does it have to start as an AIR app?

    Also, I understand that a swf can’t be loaded at runtime (if you want it’s code to work,) but can one be embedded using the mx:SWFLoader @Embed method?

    Thanks again.

  6. Hi,
    I successfully install air app using package for iOS using flex builder 3 but after running application it only shows me the progress bar does not load the application. i use the mxml file not .as will u plz help me…. thanks in advance…

  7. Hi,
    I successfully deploy an AIR application on iPad using package for iOS but after installation it does not load the application. Please help me out…
    Thanks in advance

  8. Hi,

    Awesome post. Really helping me out.
    I did have a question though.
    I’m trying to add the icon files, but its giving me an error saying it can’t find them.
    Where do I include their path in the batch file?

  9. hi,
    i’ve created a Hello World app using Flash Builder 4.5.1 for my iPodTouch 2g (ios 4.2.1). i compiled the export release .ipa file and tried syncing via iTunes. i get an error that “the .ipa is not supported in my device”. alternatively, i tried installing via Installous. this approach also throws an error saying “invalid ipa file” and thus can’t install.

    the same .ipa file works on iphone4 confirmed (but response rate of mere hello world program with one button and one label is toooo slow), and i also compiled an android .apk file and tested it in samsung galaxy s2 phone (works like a charm).

    has anyone been successful on running .ipa in ipod touch 2g or older iPhones?