解决方法
首先,您必须对Objective-C和Xcode有基本的了解.您应该能够创建一个简单的Hello World Xcode程序.一旦你知道如何做到这一点,你会发现对于每个可视窗口,你通常会有一个xib文件,一个头文件和一个实现文件.我发现开始编写一个普通的Xcode应用程序更容易,然后一旦它正常工作并且看起来应该如此,你就可以手动将这3个文件(当然还有辅助文件)拉到你的Xcode静态库项目中.所以,继续前进,我将假设你已经过了这一步.以下是有关如何使用ANE集成Xcode和Flex移动设备的一步一步说明:
>打开XCode.创建新项目. iOS – >可可触摸静态库.我打电话给我的项目FWAne
>删除FWAne.h文件.用以下内容替换FWAne.m文件的内容:
'#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];}
// ContextFinalizer().
void ContextFinalizer(FREContext ctx)
{
的NSLog(@ “ContextFinalizer”);
//清理这里
返回;
}// ContextInitializer()
void ContextInitializer(void * extData,const uint8_t * ctxType,FREContext ctx,
uint32_t * numFunctionsToTest,const FRENamedFunction ** functionsToSet)
{
的NSLog(@ “ContextInitializer”);
* numFunctionsToTest = 1;}
// ExtInitializer()
void ExtInitializer(void ** extDataToSet,FREContextInitializer * ctxInitializerToSet,
FREContextFinalizer * ctxFinalizerToSet)
{
的NSLog(@ “ExtInitializer”);
* extDataToSet = NULL;
* ctxInitializerToSet =& ContextInitializer;
* ctxFinalizerToSet =& ContextFinalizer;
}// ExtFinalizer()
void ExtFinalizer(void * 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)
>转到项目构建设置并修改以下标志(如果不这样做会导致分段错误.请花一点时间来解决这个问题.希望这是我更改的所有标志):>目标设备系列= iPhone / iPad
> Mach-O Type =静态库
>其他链接器标志= -OjbC -v
>展开Info.plist文件中的构建设置=否
>启用与共享库的链接=否>构建Xcode静态库
>现在,转到FlashBuilder并创建一个Flex库项目.请务必包含Adobe Air库
>创建将使用ExtensionContext将Flex代码连接到Xcode代码的类,如下所示:package fwane { import flash.events.EventDispatcher; import flash.events.StatusEvent; import flash.external.ExtensionContext;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;FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * 1); func[0].name = (const uint8_t*) "openFloatingWindow"; func[0].functionData = NULL; func[0].function = &openFloatingWindow; *functionsToSet = func;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); } }}
>构建FWAne swc
>接下来,您将需要一个构建脚本来编译您的ANE.这是我的build.sh脚本: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>重要的是要注意我的构建脚本:将xib编译为nib,然后将这些nib与其他资源文件(例如图像)一起包含在ANE中.请记住,静态库不能包含资源文件.
>您还需要一个ios-platformoptions.xml文件.这包括您需要的所有框架.您还可以在此处添加任何其他第三方库及其搜索路径:<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>>现在,在FlashBuilder中,创建一个示例测试应用程序项目.转到项目属性.在Flex构建路径中,确保添加了ane.也在Flex Build Packaging下 - > Apple iOS - >在此处添加ANE的本机扩展并检查包.还要在原生扩展名下添加Apple iOS SDK文件夹.最后,检查扩展是否已添加到-app.xml文件中.
>在FlashBuilder中,使用适当的打包设置在设备上创建调试配置.仔细检查是否包含和打包了本机扩展.清理项目并进行调试.如果一切顺利,将弹出“等待调试连接”窗口.在iPad上安装并启动应用程序.希望这可以帮助
C