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
Image may be NSFW.
Clik here to view.
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 |