How to create an ane that will display a floating window

How to create your own window in Xcode and integrate it with the Mobile Flex application. The natural window should act similarly to the StageWebView component, in which its own content floats in a rectangular area above the rest of the Flex application.

+6
source share
1 answer

Being a flexible programmer, it was a tedious process that took me weeks to understand. Hope this helps some other Xcode newbies.

First of all, you should have a basic understanding of Objective-C and Xcode. You should be able to create a simple Hello World Xcode program. Once you know how to do this, you will see that for each visual window there will usually be an xib file, a header file and an implementation file. I found it easier to start writing a normal Xcode application, and then when it works and looks like this, it must manually pull these 3 files (and, of course, auxiliary files) into your Xcode static library project. So, continuing, I'm going to assume that you have passed this step. Here are some step-by-step instructions on how to integrate Xcode and Flex mobile using ANE:

  • Open Xcode. Create a new project. iOS → Cocoa Touch Static Library. I named my project FWAne
  • Delete the file FWAne.h. Replace the contents of the FWAne.m file with the following text:

     '#import "FloatingWindow.h"
     '#import "FlashRuntimeExtensions.h"
    
     FREObject openFloatingWindow (FREContext ctx, void * funcData, uint32_t argc, FREObject argv [])
     {
         uint32_t parm0Length, parm1Length, parm2Length, parm3Length, parm4Length, parm5Length, parm6Length, parm7Length, parm8Length, parm9Length, parm10Length, parm11Length, parm12Length,
         const uint8_t * uparm0, * uparm1, * uparm2, * uparm3, * uparm4, * uparm5, * uparm6, * uparm7, * uparm8, * uparm9, * uparm10, * uparm11, * uparm12, * uparm13;
         FREGetObjectAsUTF8 (argv [0], & parm0Length, & uparm0);
         NSString * parm0 = [NSString stringWithUTF8String: (char *) uparm0];
         // FREGetObjectAsUTF8 (argv [1], & parm1Length, & uparm1);
         // NSString * parm1 = [NSString stringWithUTF8String: (char *) uparm1];
         // FREGetObjectAsUTF8 (argv [2], & parm2Length, & uparm2);
         // NSString * parm2 = [NSString stringWithUTF8String: (char *) uparm2];
         // FREGetObjectAsUTF8 (argv [3], & parm3Length, & uparm3);
         // NSString * parm3 = [NSString stringWithUTF8String: (char *) uparm3];
         // FREGetObjectAsUTF8 (argv [4], & parm4Length, & uparm4);
         // NSString * parm4 = [NSString stringWithUTF8String: (char *) uparm4];
         // FREGetObjectAsUTF8 (argv [5], & parm5Length, & uparm5);
         // NSString * parm5 = [NSString stringWithUTF8String: (char *) uparm5];
         // FREGetObjectAsUTF8 (argv [6], & parm6Length, & uparm6);
         // NSString * parm6 = [NSString stringWithUTF8String: (char *) uparm6];
         // FREGetObjectAsUTF8 (argv [7], & parm7Length, & uparm7);
         // NSString * parm7 = [NSString stringWithUTF8String: (char *) uparm7];
         // FREGetObjectAsUTF8 (argv [8], & parm8Length, & uparm8);
         // NSString * parm8 = [NSString stringWithUTF8String: (char *) uparm8];
         // FREGetObjectAsUTF8 (argv [9], & parm9Length, & uparm9);
         // NSString * parm9 = [NSString stringWithUTF8String: (char *) uparm9];
         // FREGetObjectAsUTF8 (argv [10], & parm10Length, & uparm10);
         // NSString * parm10 = [NSString stringWithUTF8String: (char *) uparm10];
         // FREGetObjectAsUTF8 (argv [11], & parm11Length, & uparm11);
         // NSString * parm11 = [NSString stringWithUTF8String: (char *) uparm11];
         // FREGetObjectAsUTF8 (argv [12], & parm12Length, & uparm12);
         // NSString * parm12 = [NSString stringWithUTF8String: (char *) uparm12];
         // FREGetObjectAsUTF8 (argv [13], & parm13Length, & uparm13);
         // NSString * parm13 = [NSString stringWithUTF8String: (char *) uparm13];
    
    
    NSLog(@"Initializing delegate and window"); id delegate = [[UIApplication sharedApplication] delegate]; UIWindow *window = [delegate window]; NSLog(@"Creating FloatingWindow"); FloatingWindow* fw = [[FloatingWindow alloc] initWithNibName:@"FloatingWindow" bundle:nil]; NSLog(@"Adding FloatingWindow"); [window addSubview:fw.view]; NSLog(@"Setting frame size"); fw.view.frame = CGRectMake(100, 100, 200, 200); NSLog(@"Done openFloatingWindow"); return NULL; 
    } // ContextFinalizer (). void ContextFinalizer (FREContext ctx) {NSLog (@ "ContextFinalizer"); // Cleanup Here. return } // ContextInitializer () void ContextInitializer (void * extData, const uint8_t * ctxType, FREContext ctx, uint32_t * numFunctionsToTest, const FRENamedFunction ** functionsToSet) {NSLog (@ "ContextInitializer"); * numFunctionsToTest = 1;
     FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * 1); func[0].name = (const uint8_t*) "openFloatingWindow"; func[0].functionData = NULL; func[0].function = &openFloatingWindow; *functionsToSet = func; 
    } // ExtInitializer () void ExtInitializer (void ** extDataToSet, FREContextInitializer * ctxInitializerToSet, FREContextFinalizer * ctxFinalizerToSet) {NSLog (@ "ExtInitializer"); * extDataToSet = NULL; * ctxInitializerToSet = & ContextInitializer; * ctxFinalizerToSet = & ContextFinalizer; } // ExtFinalizer () void ExtFinalizer (void * extData) {NSLog (@ "ExtFinalizer"); // Do Cleanup here. return }
  • Add FlashRuntimeExtensions.h to your Xcode project. This file exists in the / Applications / Adobe Flash Builder 4.6 / sdks / 4.6.0 / include folder

  • Add FloatingWindow.h and FloatingWindow.m (or any other files that are associated with the owner of your xib) to your Xcode project.
  • You may also need to add the UIKit structure to the xcode project (/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/UIKit.framework)
  • Go to the project build settings and change the following flags (if this does not lead to a Segmentation error, it took me a while to figure it out. I hope these are all the flags that I changed):
    • Target Device Family = iPhone / iPad
    • Type Mach-O = Static Library
    • Other linker flags = -OjbC -v
    • Expand assembly settings in the file Info.plist = No
    • Enable link to shared libraries = No
  • Creating the Xcode Static Library
  • Now go to FlashBuilder and create a Flex library project. Be sure to enable the Adobe Air libraries.
  • Create your class that will use ExtensionContext to connect Flex code to your Xcode as follows:

      package fwane
     {
         import flash.events.EventDispatcher;
         import flash.events.StatusEvent;
         import flash.external.ExtensionContext;
    
    
     public class FWAne { private static const EXTENSION_ID : String = "fwane.FWAne"; private var context : ExtensionContext; public function FWAne() { context = ExtensionContext.createExtensionContext( EXTENSION_ID, null ); if (context == null) { trace("WARNING: ExtensionContext cannot initialize"); } } public function openFloatingWeendow(fileName : String) : void { trace("Calling openFloatingWeendow"); context.addEventListener( StatusEvent.STATUS, onAneWinHander ); trace("Invoking native call"); context.call( "openFloatingWindow", fileName); trace("Returning from openFloatingWeendow"); } private function onAneWinHander( event : StatusEvent ) : void { trace(event.level); } } 
    }
  • Build FWAne swc

  • Next, you'll need a build script to compile your ANE. Here is my build.sh script:

     export XLIB = "/ Users / christo.smal / Library / Developer / Xcode / DerivedData / wherever-lib.a"
     export CERT = "/ wherever / if / you / want / to / sign / ane.p12"
     export FLEXLIBPATH = "../ Path / of / flex / library / project"
     export XIBPATH = "/ Path / of / where / xib / files / are"
     export SWCFNAME = "FWAne.swc"
     export ANEFNAME = "FWAne.ane"
    
     ls -la $ xlib
    
     echo Copying files ...
      rm -rf debug / *
     cp $ FLEXLIBPATH / src / extension.xml.
     cp $ FLEXLIBPATH / bin / $ SWCFNAME.
      cp $ xlib ./debug
    
     '# copy resource files such as images to debug folder
     cp /path/to/my/images/referenced/from/xcode/*.png ./debug
    
     echo Compiling xib''s
    
     cp $ XIBPATH / *. xib ./debug
     cp /wherever/FloatingWindow.xib ./debug
    
     / Developer / usr / bin / ibtool --errors --warnings --notices --output-format human-readable-text --compile debug / FloatingWindow.nib debug / FloatingWindow.xib --sdk / Developer / Platforms / iPhoneOS. platform / Developer / SDKs / iPhoneOS5.0.sdk
    
     rm -rf debug / *. xib
    
    
     echo Extracting library.swc ...
     cp $ SWCFNAME kak
     cd kak
     unzip -xo $ SWCFNAME
     cp -X library.swf ../debug
     cd ..
    
     echo Copying some more files ...
     rm -rf debug / *. ane
     cp extension.xml debug
    
     echo Building ANE ... 
     '# -package -target ane / extension.xml -swc -platform -C.
     / Applications / Adobe \ Flash \ Builder \ 4.6 / sdks / 4.6.0 / bin / adt -package -target ane debug / unsigned.ane extension.xml -swc $ SWCFNAME -platform iPhone-ARM -platformoptions ios-platformoptions.xml - C debug.
    
     echo Signing ANE ...
     '# / Applications / Adobe \ Flash \ Builder \ 4.6 / sdks / 4.6.0 / bin / adt -sign -storetype pkcs12 -keystore $ CERT -storepass password -target ane debug / unsigned.ane $ ANEFNAME
     cp debug / unsigned.ane $ ANEFNAME
    
     echo done
    
  • It is important to note that my build of the script: xibs is compiled into nibs, and then these nibs, along with other resource files (like images), are then included in the ANE. Remember that static libraries cannot contain resource files.

  • You will also need the ios-platformoptions.xml file. This includes all the structures you need. You can also include any additional third-party libraries with their search paths:

      <platform xmlns = "http://ns.adobe.com/air/extension/3.1">
         <sdkVersion> 5.0 </sdkVersion>
         <linkerOptions>
             <option> -framework Foundation </option>
             <option> -framework UIKit </option>
             <option> -framework QuartzCore </option>
             <option> -framework CoreGraphics </option>
             <! - option> -lthirdparty </option>
             <option> -L / searhPath / for / thirdlibrary </option-->
         </linkerOptions>
     </platform>
    
  • Now, in FlashBuilder, create a sample test application. Go to the project properties. In the Flex build path, make sure ane is added. Also in Flex Build Packaging → Apple iOS → Native Extensions, ANE has been added and the package is being checked. Also add the Apple iOS SDK folder to your own extensions. Finally, make sure the extension is added to the -app.xml file.

  • In FlashBuilder, create a debug configuration on the device with the appropriate packaging settings. Double check that the internal extension is included and packaged. Clean up the project and debug it. If all goes well, the Pending Debugging window appears. Install and run the application on the iPad.

Hope this helps

FROM

+11
source

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


All Articles