Flex 4.6 compiler check if compilation for iOS or Android

I am creating a mobile application for iOS and Android, with flashbuilder 4.6, Flex SDK 4.6.

I use ANE for Google cloud messaging that I would like to skip when compiling for iOS. Are there any definitions in flashbuilder to check if its compiling for iOS or Android, so I can skip the GCM import. I don’t want to change my compiler every time I compile my application.

Another way is to use the IF statement in compiler arguments:

if (compiling for ios) -define+=CONFIG::IOS,true else -define+=CONFIG::IOS,false 

Is it possible to do something similar or is there a built-in compiler that I can use in my code?

EDIT: package managers have 3 classes:

  • NotificationManager.as
  • NotificationManagerIOS.as (Singleton for iOS, uses RemoteNotification from Air)
  • NotificationManagerAndroid.as (Singleton for Android, uses ANE, which does not support iOS)

Compiling for android is fine, compiling for iOS gives errors in classes from ANE.

NotificationManager.as:

 package managers { public class NotificationManager { public static function getInstance():NotificationManager { var ios:Boolean = (Capabilities.manufacturer.indexOf("iOS") != -1); if (ios) { return NotificationManagerIOS.getInstance(); } else { return NotificationManagerAndroid.getInstance(); } } } } 
+4
source share
1 answer

Flash Player AVM2 is a virtual machine that uses the JIT compiler, so what you want to do is not possible. However, there are two common ways to solve this problem:

  • Compile separately for each deployment target, especially if the built-in support files for the OS are large. You can set up an IDE project for several folders so that compilation for each purpose simply opens each folder and composes the contents. Read Christian Cantrell Writing AIR Multiscreen Applications to see how you can customize your project for individual deployment goals.

  • If the built-in, supported OS support files are small or you only need to manage one project folder, you can direct the runtime to use the corresponding file, specifying its purpose using flash.system.Capabilities :

    var isIOS:Boolean = (Capabilities.manufacturer.indexOf("iOS") != -1);

    var isAndroid:Boolean = (Capabilities.manufacturer.indexOf("Android") != -1)

+2
source

Source: https://habr.com/ru/post/1489242/


All Articles