=================================
=================================
=================================
출처: http://airdev.tistory.com/623
Adobe의 NetworkInfo ANE에 대한 올바른 사용법
http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/networkinfo.html
위 페이지의 NetworkInfo ANE 샘플을 이용해 보신 분 중에 iOS에서 작동을 안해서 포기하신 분들이 있으실 것 같습니다. 그래서 대부분 아래 URL의 ANE를 쓰실텐데요.
https://github.com/freshplanet/ANE-Network-Info
저의 경우는 freshplanet ANE가 다른 ANE와 충돌이 발생했습니다. 그래서 다시 Adobe의 ANE를 살펴봤습니다.
자세히 보다보니 import com.adobe.nativeExtensions.Networkinfo.NetworkInfo; 가 보입니다. 혹시 본인이 썼던 소스의 NetworkInfo 가 flash.net.NetworkInfo 라면 잘못 사용한 것입니다. 처음 URL의 소스를 다운받으시면 ANE가 들어 있으니 프로젝트에 포함시켜서 사용해 보세요. 잘 됩니다.
덤으로..hardwareAddress를 이용하면 MAC Address를 얻을 수 있는데요. 여러개가 나와서 뭘 써야할지 모르는 분들은 아래 코드로 실행을 해보세요.
var ntf:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
for each (var interfaceObj:NetworkInterface in ntf)
{
trace(interfaceObj.active + ", " + interfaceObj.name + ", " +interfaceObj.hardwareAddress + "\n");
}
그러면 하나만 active가 true일 것입니다. 그것의 이름은 'en0'일거고요. Objective-C 소스들을 보니 모두 'en0'의 값을 가져와서 쓰고 있었습니다. 그러니 'en0'이 고유한 MAC Address라고 생각하시면 될 것입니다.
=================================
=================================
=================================
<iPhone>
<InfoAdditions>
<![CDATA[
<key>UIDeviceFamily</key>
<array>
<string>2</string>
</array>
<key>UIApplicationExitsOnSuspend</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIRequiresPersistentWiFi</key>
<string>NO</string>
]]>
</InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
</iPhone>
<extensions>
<extensionID>com.adobe.ane.productStore</extensionID> /*결제*/
<extensionID>com.adobe.nativeExtensions.Networkinfo</extensionID> //네트워크정보
</extensions>
위와같이 xml 빌드정보에 넣어주는것을 잊지 말자.
=================================
=================================
=================================
출처: http://blog.naver.com/babdeuk/90163826679
안드로이드와 iOS에서 모두 NetworkInfo 가져 오기 air mobile 2013/02/05 09:28 http://blog.naver.com/babdeuk/90163826679 전용뷰어 보기 |
Problem
You want to get NetworkInfo between iOS and Android but one uses a Native Extension (iOS)
Solution
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.
Detailed explanation
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()
+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.
출처) http://cookbooks.adobe.com/post_Getting_NetworkInfo_from_both_Android_and_iOS-19473.html
샘플) http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/networkinfo.html
자세한 설명) http://airdev.tistory.com/623
[출처] 안드로이드와 iOS에서 모두 NetworkInfo 가져 오기|작성자 다현아빠
=================================
=================================
=================================
출처: http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/networkinfo.html
Requirements
Prerequisite knowledge
Familiarity with building mobile AIR applications for iOS, including familiarity with Objective C and Xcode.
Required third-party products
User level
Intermediate
Required products
Sample files
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
NetworkInfoiOSLibrary. - 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.name, interfaceObj.displayName, interfaceObj.active, // 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:
More Like This
=================================
=================================
=================================