So you want to know what’s in an AIR Native Extension for iOS and how it fits together? I know, Adobe’s online manual has it all, which is great. It is also a problem, as you are left to sift through tones of pages of information, just to get a general idea.
This post is a collection of infographics, which will give you a bird’s eye view of how a native extension for iOS fits together. You can also use it as a checklist for the files and settings you need to set up in your extension.
What is an ActionScript Native Extension?
A library, packaged into an .ane file. ANE stands for ActionScript Native Extension. An ANE allows you to extend your mobile app with functionality, which is not available to you via ActionScript. To use an ANE, you package it into your iOS App Store package – the .ipa file that you put on your device or release on Apple’s App Store:
Wait, how do I implement the ANE, if ActionScript is not an option?
You use native code. When you implement a Native Extension for iOS, this would typically be Objective-C.
This is what goes in your Native Extension:
- You implement your extended functionality as a native library – an .a file for iOS. There you can make direct calls to the iOS SDK.
- Then you slap on an ActionScript interface on it. This will be an ActionScript AIR library – a .swf file, which will make calls into the AIR Runtime, which in turn will call the native code and pass results, arguments or events back to your AIR library.
- The native library and the AIR library get packaged together in an .ane file.
How do the libraries and the application code work together?
In order to get it all to click, you have to do some formal introductions.
Introduce the two native libraries to each other
- In the AIR library’s ActionScript code create an instance of flash.external.ExtensionContext. This is the class that you will be using to make calls into the native side.
Tip: An ExtensionContext instance is created for a particular Extension ID and a particular Extension type and is passed as an argument to all calls into native code.
- Add Extension descriptors to your AIR library: these are two XML files with information about the extension and the native library:
- extension.xml contains an Extension ID – a unique string identifier, the name of the native library file and the names of the extension initializer and finalizer functions. The extension initializer and finalizer are called by the AIR runtime when the extension is loaded and unloaded, respectively. For details on what these look like and how they work have a look at our next post, Adobe AIR Native Extensions for iOS – Initialization and Finalization
- platformoptions.xml contains platform-specific information. For iOS this would include the version of the iOS SDK and a list of iOS SDK frameworks that the native library uses, for example:
Introduce the ANE to the Air Mobile APP
- Add your Extension ID to the application descriptor file, normally called your-app-name-app.xml.
- Add the ANE to your project settings:
- add the path to the ANE to your Flex Build Path
- include the ANE in your Flex Build Packaging; here you may also have to add a path to the iOS SDK:
Introductions done, now what?
Next, you will have to make it possible for the AIR Runtime to load and unload your extension. For this purpose you need to implement a couple of pairs of functions:
- Extension Initializer and Finalizer
- Extension Context Initializer and Finalizer
For what these are and how the AIR Runtime calls them, read our next post, Adobe AIR Native Extensions for iOS – Initialization and Finalization.