如何创建本机显示浮动窗口的 ANE

发布于 2024-12-28 13:34:12 字数 108 浏览 5 评论 0原文

如何在 Xcode 中创建本机窗口并将其与 Mobile Flex 应用程序集成。本机窗口的行为应与 StageWebView 组件类似,其中本机内容浮动在 Flex 应用程序其余部分上方的矩形区域中。

How to create a native window in Xcode and integrate it with a Mobile Flex application. The native window should act similar as the StageWebView component whereby the native content floats in a rectangular area over the rest of the Flex app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风透绣罗衣 2025-01-04 13:34:12

作为一名 Flex 程序员,这是一个乏味的过程,我花了几周的时间才弄清楚。希望这会对其他 Xcode 新手有所帮助。

首先,你必须对 Objective-C 和 Xcode 有基本的了解。您应该能够创建一个简单的 Hello World Xcode 程序。一旦您知道如何执行此操作,您就会发现对于每个可视窗口,您通常都会有一个 xib 文件、一个头文件和一个实现文件。我发现开始编写普通的 Xcode 应用程序更容易,然后一旦它开始工作并且看起来像应该的那样,您可以手动将这 3 个文件(当然还有帮助程序文件)拉到您的 Xcode 静态库项目中。所以,继续,我假设您已经完成了这一步。以下是有关如何使用 ANE:

  • Open XCode 集成 Xcode 和 Flex mobile 的一些分步说明。创建新项目。 iOS-> Cocoa Touch 静态库。我将我的项目命名为 FWAne
  • 删除 FWAne.h 文件。将 FWAne.m 文件的内容替换为以下内容:

    <前>
    '#import“浮动窗口.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、parm13Length;
    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(@"初始化委托和窗口");
    id 委托 = [[UIApplication共享应用] 委托]; 
    UIWindow *window = [委托窗口];
    NSLog(@"创建浮动窗口");
    FloatingWindow* fw = [[FloatingWindow alloc] initWithNibName:@"FloatingWindow" bundle:nil];
    NSLog(@"添加浮动窗口");
    [窗口addSubview:fw.view];
    NSLog(@"设置帧大小");
    fw.view.frame = CGRectMake(100, 100, 200, 200);
    NSLog(@"打开FloatingWindow完成");
    返回空值;
    

    }

    // ContextFinalizer()。
    void ContextFinalizer(FREContext ctx)
    {
    NSLog(@"ContextFinalizer");
    //这里清理。
    返回;
    }

    // 上下文初始化器()
    void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
    uint32_t* numFunctionsToTest, const FRENamedFunction** 函数集)
    {
    NSLog(@"ContextInitializer");
    *要测试的函数数 = 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;
    

    }

    // 外部初始化器()
    void ExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
    FREContextFinalizer* ctxFinalizerToSet)
    {
    NSLog(@"ExtInitializer");
    *extDataToSet = NULL;
    *ctxInitializerToSet = &ContextInitializer;
    *ctxFinalizerToSet = &ContextFinalizer;
    }

    // ExtFinalizer()
    无效 ExtFinalizer(无效* extData) {
    NSLog(@"ExtFinalizer");
    // 在这里进行清理。
    返回;
    }

  • 将 FlashRuntimeExtensions.h 添加到您的 Xcode 项目。该文件位于 /Applications/Adobe Flash Builder 4.6/sdks/4.6.0/include 文件夹下

  • 将 FloatingWindow.h 和 FloatingWindow.m(或与您的 xib 所有者关联的任何文件名称)添加到您的 Xcode 项目。
  • 您可能还需要将 UIKit 框架添加到 xcode 项目 (/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/UIKit.framework)
  • 转到项目构建设置并修改以下标志(不这样做会导致分段错误。我花了一段时间才弄清楚这一点。希望这是我更改的所有标志):
    1. 目标设备系列 = iPhone/iPad
    2. Mach-O 类型 = 静态库
    3. 其他链接器标志 = -OjbC –v
    4. 展开 Info.plist 文件中的构建设置 = 否
    5. 启用与共享库的链接 = 否
  • 构建 Xcode 静态库
  • 现在,转到 FlashBuilder 并创建一个 Flex 库项目。确保包含 Adob​​e Air 库
  • 创建将使用 ExtensionContext 将 Flex 代码连接到 Xcode 代码的类,如下所示:

    包fwane
    {
        导入 flash.events.EventDispatcher;
        导入 flash.events.StatusEvent;
        导入 flash.external.ExtensionContext;
    
    
    公共类 FWAne 
    {
    
        私有静态 const EXTENSION_ID : String = "fwane.FWAne";
    
        私有变量上下文:ExtensionContext;
    
        公共函数 FWAne()
        {
            上下文 = ExtensionContext.createExtensionContext( EXTENSION_ID, null );
            如果(上下文==空){
                跟踪(“警告:ExtensionContext无法初始化”);
            }
        }
    
        公共函数 openFloatingWeendow(fileName : String) : void {
            跟踪(“调用openFloatingWeendow”);
            context.addEventListener( StatusEvent.STATUS, onAneWinHander );
            trace("正在调用本机调用");
            context.call(“openFloatingWindow”, 文件名);
            trace("从 openFloatingWeendow 返回");
        }
    
        私有函数 onAneWinHander( 事件 : StatusEvent ) : void
        {
            跟踪(事件级别);
        }
    
    }
    

    }

  • 构建 FWAne swc

  • 接下来,您将需要构建编译 ANE 的脚本。这是我的 build.sh 脚本:

    <前>
    导出XLIB =“/Users/christo.smal/Library/Developer/Xcode/DerivedData/wherever-lib.a”
    导出 CERT="/wherever/if/you/want/to/sign/ane.p12"
    导出 FLEXLIBPATH="../路径/of/flex/library/project"
    导出 XIBPATH="/路径/of/where/xib/files/are"
    导出 SWCFNAME="FWAne.swc"
    导出 ANEFNAME="FWAne.ane"

    ls -la $XLIB

    echo 正在复制文件...
    rm -rf 调试/*
    cp $FLEXLIBPATH/src/extension.xml 。
    cp $FLEXLIBPATH/bin/$SWCFNAME 。
    cp $XLIB ./debug

    '# 将图片等资源文件复制到debug文件夹
    cp /path/to/my/images/referenced/from/xcode/*.png ./debug

    echo 编译 xib's

    cp $XIBPATH/*.xib ./debug
    cp /wherever/FloatingWindow.xib ./debug

    /Developer/usr/bin/ibtool --errors --warnings --notices --output-format 人类可读文本 --compile debug/FloatingWindow.nib debug/FloatingWindow.xib --sdk /Developer/Platforms/iPhoneOS。平台/开发者/SDKs/iPhoneOS5.0.sdk

    rm -rf 调试/*.xib

    echo 正在提取library.swc ...
    cp $SWCFNAME kak
    CD卡克
    解压缩 -xo $SWCFNAME
    cp -X 库.swf ../调试
    光盘 ..

    echo 正在复制更多文件...
    rm -rf 调试/*.ane
    cp 扩展名.xml 调试

    回声大厦 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 调试 .

    echo 签名 ANE ...
    '#/Applications/Adobe\ Flash\ Builder\ 4.6/sdks/4.6.0/bin/adt -sign -storetype pkcs12 -keystore $CERT -storepass 密码 -target ane debug/unsigned.ane $ANEFNAME
    cp debug/unsigned.ane $ANEFNAME

    回声完成

  • 关于我的构建脚本的重要注意事项:xib 被编译为 nib,然后这些 nib 与其他资源文件(例如图像)一起包含在 ANE 中。请记住,静态库不能包含资源文件。

  • 您还需要一个 ios-platformoptions.xml 文件。这包括您需要的所有框架。您还可以在此处包含任何其他第 3 方库及其搜索路径:

    <平台 xmlns="http://ns.adobe.com/air/extension/3.1">
        5.0
        <链接器选项>
            <选项>-框架基础
            <选项>-UIKit框架
            <选项>-QuartzCore框架
            <选项>-框架CoreGraphics
            
        
    
    
  • 现在,在 FlashBuilder 中创建一个示例测试应用程序项目。转到项目属性。在 Flex 构建路径中,确保添加了 ane。也在 Flex Build Packaging 下 ->苹果 iOS ->本地扩展 ANE 被添加到那里并检查包。还要在本机扩展下添加 Apple iOS SDK 文件夹。最后,检查扩展是否已添加到 -app.xml 文件中。

  • 在 FlashBuilder 中,使用适当的打包设置在设备上创建调试配置。仔细检查本机扩展是否已包含并打包。清理项目并调试。如果一切顺利,则会弹出“等待调试连接”窗口。在 iPad 上安装并启动应用程序。

希望这对

C有帮助

Being a flex programmer, this was a tedious process that took me weeks to figure out. Hope this will helps some other Xcode newbies.

First of all, you must 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'll see that for each visual window you'll typically have a xib file, a header file and an implementation file. I found that it is easier to start of writing a normal Xcode application, and then once it is working and looking like it should, you manually pull these 3 files (and of course the helper files) over to your Xcode static library project. So, moving on, I'm going to assume that you're past this step. Here are some step by step instructions on how to integrate Xcode and Flex mobile, using ANE:

  • Open XCode. Create new project. iOS -> Cocoa Touch Static Library. I called my project FWAne
  • Delete FWAne.h file. Replace contents of FWAne.m file with the following:

    '#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, parm13Length;
        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 the FlashRuntimeExtensions.h to your Xcode project. This file exists under the /Applications/Adobe Flash Builder 4.6/sdks/4.6.0/include folder

  • Add FloatingWindow.h and FloatingWindow.m (or whatever the files are called that is associated with the owner of your xib) to your Xcode project.
  • You might also need to add the UIKit framework to the xcode project (/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/UIKit.framework)
  • Go to project build settings and modify the following flags (Failure to do so results in Segmentation fault. Took me a while to figure this out. Hope this is all the flags that I changed):
    1. Target device family = iPhone/iPad
    2. Mach-O Type = Static Library
    3. Other linker flags = -OjbC –v
    4. Expand Build settings in Info.plist file = No
    5. Enable Linking with shared libraries = No
  • Build the Xcode static library
  • Now, go to FlashBuilder and create a Flex library project. Be sure in include the Adobe Air libraries
  • Create your class that will use ExtensionContext to wire the Flex code to your Xcode code like so:

    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 the FWAne swc

  • Next, you are going to require a build script to compile your ANE. Here's 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
    
  • Important to note about my build script: The xibs are compiled to nibs, and then these nibs together with other resource files (such as images) are then included in the ANE. Remember that static libs cannot contain resource files.

  • You would also require an ios-platformoptions.xml file. This is to include all frameworks you require. You can also include any additional 3rd party libs with their search paths here:

    <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 project. Go to project properties. In Flex build path, make sure the ane is added. Also under Flex Build Packaging -> Apple iOS -> Native extensions the ANE is added there and package is checked. Also add the Apple iOS SDK folder under native extensions. Finally, check that the extension is added in the -app.xml file.

  • In FlashBuilder, create a debug configuration on device with the appropriate packaging settings. Double check that the native extension is included and packaged. Clean the project and debug. If all goes well the 'Waiting for debug connection' window pops up. Install and launch the app on the iPad.

Hope this helps

C

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文