You want to get NetworkInfo between iOS and Android but one uses a Native Extension (iOS)
The methods that the NetworkInfo Native extension for iOS uses are the same as the native ActionScript. After adding the native extension to your Flex project, create an interface that defines the methods you want to use. Then create two classes that implement that interface.
The ActionScript is the same between naive extension and what is built into AIR, but the packages are different.
For example if you wanted NetworkInfo just using AIR (works on Android)
import flash.net.NetworkInfo; import flash.net.NetworkInterface;
Using the naive extension looks like this:
import com.adobe.nativeExtensions.Networkinfo.InterfaceAddress; import com.adobe.nativeExtensions.Networkinfo.NetworkInfo; import com.adobe.nativeExtensions.Networkinfo.NetworkInterface;
So you end up with problems if you try to use both in the same class. So if you create an interface you can seperate the implementation beween two classes and call what you need at runtime.
package interfaces{
public interface INetworkInfo
{
function getNetworkInfo();
}
}
Class example:
package NetworkInfo
{
import com.adobe.nativeExtensions.Networkinfo.InterfaceAddress;
import com.adobe.nativeExtensions.Networkinfo.NetworkInfo;
import com.adobe.nativeExtensions.Networkinfo.NetworkInterface;
public class IOSNetworkInfo implements INetworkInfo
{
public function getNetworkInfo():void
{
var _netInterface:Vector.<NetworkInterface> = com.adobe.nativeExtensions.Networkinfo.NetworkInfo.networkInfo.findInterfaces();
for each (var interfaceObj:NetworkInterface in _netInterface){
trace("Interface Name:" + interfaceObj.name + "\n" );
trace("Hardware Address:" + interfaceObj.hardwareAddress + "\n");
}
}
}
}
You also write a second class for the Non iOS version.
Then in your main application you use the capabilities class to figure out witch to use.
var networkInfoObj:INetworkInfo //datatype is the interface
if(Capabilities.os == "iPhone3,1"){
networkInfoObj = new IOSNetworkInfo();
}else{
networkInfoObj = new AndroidNetworkInfo();
}
At the end you call the method that is outlined in the interface.
Since both classes implment the same interface it wont matter if your asking for iOS info or Andoid info.
networkInfoObj.getNetworkInfo()
+