Prerequisite knowledge

Familiarity with building mobile AIR applications for iOS, including familiarity with Objective C and Xcode.


Required third-party products

User level


Note: By clicking the download link for any source examples on this page, you acknowledge that you have read and agree to the Adobe AIR SDK License Agreement. These files are considered Sample Code.

The NetworkInfo class is a native extension for Adobe AIR. It allows AIR application developers, from ActionScript, to get information for each network interface.

ActionScript already provides a NetworkInfo class that works on desktop and AIR for TV devices. This native extension provides a similar class so that AIR applications for iOS can also get information for each network interface.

The attached ZIP files contain:

  • The ActionScript library in the directory NetworkInfoActionScriptLibrary: This directory contains the Flash Builder project for creating the ActionScript side of the NetworkInfo extension.
  • The iOS native library in the directory NetworkInfoiOSLibrary: This directory contains an Xcode project for creating the iOS native side of the NetworkInfo extension. To build the Xcode project, first copy FlashRuntimeExtension.h from <AIR_SDK>/include/FlashRuntimeExtensions.h to the directory
  • A directory called Binaries: This directoyt contains everything the AIR application developer needs to use the native extension: the ANE file, the SWC file, and a text file that contains the extension ID.
  • A directory called NetworkInfoUsageApp: This directory contains a sample AIR application that uses the NetworkInfo native extension.

The ActionScript library

The ActionScript library contains the NetworkInfo class. The NetworkInfo class provides the AIR application this public method and property:

  • public static function get networkInfo(): NetworkInfo
  • public function findInterfaces(): Vector.<NetworkInterface>

The NetworkInfo object is a singleton. The AIR application gets the single NetworkInfo object using the static networkInfo property.

The findInterfaces() method returns a Vector of NetworkInterface objects. The NetworkInterface class is also defined in the ActionScript library. The NetworkInterface class provides these public properties:

  • public function get name():String
  • public function get displayName():String
  • public function get mtu():int
  • public function get hardwareAddress():String
  • public function get active():Boolean
  • public function get addresses():Vector.<InterfaceAddress>

The addresses() property returns a Vector of InterfaceAddress objects. The InterfaceAddress class is also defined in the ActionScript library. It contains these public properties:

  • public function get address():String
  • public function get broadcast():String
  • public function get prefixLength():int
  • public function get ipVersion():String

Note: The public functions and properties of the classes in the NetworkInfo extension—NetworkInfo, NetworkInterface, and InterfaceAddress—correspond with the public functions and properties in the existing ActionScript classes by the same name. See NetworkInfo, NetworkInterface, and InterfaceAddress in the ActionScript 3 Reference for the Adobe Flash Platform.

Application usage

To use the NetworkInfo extension, an AIR application does the following:

  • Get the NetworkInfo singleton object by accessing the static property NetworkInfo.networkInfo .
  • Call the NetworkInfo singleton object's findInterfaces() method to get a list of network interfaces.

For example:

var ntf:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();

Note: Do not call new NetworkInfo() . Trying to create an instance of the NetworkInfo class in this manner throws an exception.

Then you can process each NetworkInterface object in the returned Vector. For example:

for each (var interfaceObj:NetworkInterface in ntf) { // Access, interfaceObj.displayName,, // interfaceObj.hardwareAddress, and interfaceObj.mtu for each(var address:InterfaceAddress in interfaceObj.addresses) { // Access address.address, address.broadcast, address.ipVersion, and address.prefixLength } }

Note that the prefixLength field of the InterfaceAddress class is not supported. Its value is always -1 .

The iOS native library

The iOS native library is implemented in Objective C, using the native extension C API. The native library contains examples of these native extension C APIs:

  • The extension initializer and finalizer, using the signatures of FREInitializer()and FREFinalizer().
  • The context initializer and finalizer, using the signatures of FREContextInitializer() and FREContextFinalizer() .
  • A native function, findInterfaces(), that uses the signature of FREFunction().
  • FRENewObject()
  • FRENewObjectFromBool()
  • FRENewObjectFromInt32()
  • FRENewObjectFromUTF8()
  • FRESetArrayElementAt()

The native function findInterfaces() calls the iOS API getifaddrs() function to get a linked list of the device's network interfaces. The function processes the elements in the list, returning an array of NetworkInterface objects to the ActionScript side of the extension.

Where to go from here

For more information about developing native extensions for Adobe AIR, see:

For more information about using a native extension in an AIR application, see: