来源:http://bbs.9ria.com/thread-102037-1-1.html

最近看到本版块的很多关于NativeExtension的应用。但是都是在Android下面的应用。也有很多朋友在线上问我这个问题,今天晚上特写了一篇NativeExtension在IOS的应用,首先,我们做准备工作,下载AIR3.0及其SDK,当然我们也可以下载Flash Builder 4.6的Prelease版本,4.6可以直接添加ANE文件,进行最后的打包Ipa工作。省了最后的命令行工作,对新手来说,建议采用Flash Builder 4.6.,下载地址论坛里的兄弟贡献出来了,http://bbs.9ria.com/thread-100284-1-1.html

下面开始制作ANE文件,

1,启动Xcode,在IOS-》Frameworkd&Library下面,创建一个Cocoa Touch Static Library的项目(我们暂时将项目取名为:CoolExpLibANEIOS)。
2,OK,创建好之后,从你下载的SDK目录下,找到Include文件夹,找到里面的FlashRuntimeExtensions.h,通过项目添加FlashRuntimeExtensions.h文件
3,新建一个Object-C Class文件,此时会产生一个.h一个.m的文件,此时可以把.h文件删除,留一个.m的文件就行了。在这里我们暂定这个M的文件叫CoolExpLibANE.m文件。
4,下面是该文件的内容:我这里定义了两个方法供测试用,一个叫ShowIconBadageNumber,另外一个叫InitNativeCode。其他的代码都是必需的。

  1. #import "FlashRuntimeExtensions.h"
  2. #import <AudioToolbox/AudioServices.h>
  3. #import <UIKit/UIKit.h>
  4. FREObject ShowIconBadageNumber(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
  5. int32_t t;
  6. FREGetObjectAsInt32(argv[0], &t);
  7. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:t];
  8. return argv[0];
  9. }
  10. // InitNativeCode()
  11. //
  12. // An InitNativeCode function is necessary in the Android implementation of this extension.
  13. // Therefore, an analogous function is necessary in the iOS implementation to make
  14. // the ActionScript interface identical for all implementations.
  15. // However, the iOS implementation has nothing to do.
  16. //此方法参考Adobe的官方例子,Vibration的。具体不明白的可以看注释。
  17. FREObject InitNativeCode(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
  18. NSLog(@"Entering InitNativeCode()");
  19. // Nothing to do.
  20. NSLog(@"Exiting InitNativeCode()");
  21. return NULL;
  22. }
  23. // ContextInitializer()
  24. //
  25. // The context initializer is called when the runtime creates the extension context instance.
  26. void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
  27. uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) {
  28. NSLog(@"Entering ContextInitializer()");
  29. *numFunctionsToTest = 2;
  30. //这地方 ,如果是两个方法有两个2,如果是三个方法就是3了。当然你可以自己看着定义了。
  31. FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * 2);
  32. //这地方定义方法名
  33. //Just for consistency with Android
  34. func[0].name = (const uint8_t*) "initNativeCode";
  35. func[0].functionData = NULL;
  36. func[0].function = &InitNativeCode;
  37. //这地方定义方法名
  38. func[1].name = (const uint8_t*) "ShowIconBadageNumber";
  39. func[1].functionData = NULL;
  40. func[1].function = &ShowIconBadageNumber;
  41. *functionsToSet = func;
  42. NSLog(@"Exiting ContextInitializer()");
  43. }
  44. // ContextFinalizer()
  45. //
  46. // The context finalizer is called when the extension's ActionScript code
  47. // calls the ExtensionContext instance's dispose() method.
  48. // If the AIR runtime garbage collector disposes of the ExtensionContext instance, the runtime also calls
  49. // ContextFinalizer().
  50. void ContextFinalizer(FREContext ctx) {
  51. NSLog(@"Entering ContextFinalizer()");
  52. // Nothing to clean up.
  53. NSLog(@"Exiting ContextFinalizer()");
  54. return;
  55. }
  56. // ExtInitializer()
  57. //
  58. // The extension initializer is called the first time the ActionScript side of the extension
  59. // calls ExtensionContext.createExtensionContext() for any context.
  60. void ExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
  61. FREContextFinalizer* ctxFinalizerToSet) {
  62. NSLog(@"Entering ExtInitializer()");
  63. *extDataToSet = NULL;
  64. *ctxInitializerToSet = &ContextInitializer;
  65. *ctxFinalizerToSet = &ContextFinalizer;
  66. NSLog(@"Exiting ExtInitializer()");
  67. }
  68. // ExtFinalizer()
  69. //
  70. // The extension finalizer is called when the runtime unloads the extension. However, it is not always called.
  71. void ExtFinalizer(void* extData) {
  72. NSLog(@"Entering ExtFinalizer()");
  73. // Nothing to clean up.
  74. NSLog(@"Exiting ExtFinalizer()");
  75. return;
  76. }

复制代码

5,Build项目,会在项目文件夹Products生成一个.a 的文件,复制出来,我们在打包ANE的时候要用。

好了。IOS项目创建完毕。下一篇介绍如果创建ActionScript Library。

项目源文件下载在第四篇

[AIR] NativeExtension在IOS下的开发实例 --- IOS项目的创建 (一)的更多相关文章

  1. [AIR] NativeExtension在IOS下的开发实例 --- 新建项目测试ANE(四)

    来源:http://bbs.9ria.com/thread-102043-1-1.html 通过前面的努力,好了,我们终于得到了一个ANE文件了.下面我们开始新建一个Flex Mobile项目做一下测 ...

  2. [AIR] NativeExtension在IOS下的开发实例 --- Flex库项目的创建(二)

    来源:http://bbs.9ria.com/thread-102038-1-1.html 上一章,我已经介绍了如果创建IOS库文件,并定义了两个方法ShowIconBadageNumber和Init ...

  3. [AIR] NativeExtension在IOS下的开发实例 --- ANE文件的打包(三)

    来源:http://bbs.9ria.com/thread-102041-1-1.html 好了,前面的准备工作做的差不多了.此时我们应用有下面几个文件:extension.xml    CoolEx ...

  4. iOS下OpenCV开发用OC还是Swift

    本文为作者原创,转载请注明出处(http://www.cnblogs.com/mar-q/)by 负赑屃 其实标题中这个问题并不准确,准确的说法应该是iOS下的OpenCV开发是使用OC还是Swift ...

  5. iOS下OpenCV开发配置的两个常见问题(sign和link)

    本文为作者原创,转载请注明出处(http://www.cnblogs.com/mar-q/)by 负赑屃 先上可以运行官方推荐的<OpenCV for iOS samples>的demo链 ...

  6. Android studio 下 JNI 开发实例

    在AS中进行 NDK 开发之前,我们先来简单的介绍几个大家都容易搞懵的概念: 到底什么是JNI,什么是NDK? 何为“交叉编译”? 先看什么是 JNI?JNI 的全称就是 Java Native In ...

  7. AJ学IOS 之ipad开发qq空间项目横竖屏幕适配

    AJ分享,必须精品 一:效果图 先看效果 二:结构图 如图所示: 其中用到了UIView+extension分类 Masonry第三方框架做子控制器的适配 NYHomeViewController对应 ...

  8. iOS下的WiFi开发

    iOS下Wi-Fi开发需要添加依赖库SystemConfiguration.framework,在需要使用Wi-Fi信息的控制器下引入头文件#import <SystemConfiguratio ...

  9. 移动端底部fixed固定定位输入框ios下不兼容

    简短记录下最近开发移动端项目碰到的小坑,产品需求做一个售后对话页面,底部固定输入框,和微信对话差不多,但是在ios下,fixed失效,输入框被虚拟键盘挡住,在安卓下是正常的. 尝试过网上说的很多方法, ...

随机推荐

  1. 数据库sql优化总结之5--数据库SQL优化大总结

    数据库SQL优化大总结 小编最近几天一直未出新技术点,是因为小编在忙着总结整理数据库的一些优化方案,特此奉上,优化总结较多,建议分段去消化,一口吃不成pang(胖)纸 一.百万级数据库优化方案 1.对 ...

  2. 蓝绿部署、A/B测试以及灰度发布(金丝雀发布)

    过去的10多年里,很多大公司都在使用蓝绿部署,安全.可靠是这种部署方式的特点.蓝绿部署虽然算不上”Sliver Bullet“,但确实很实用.在有关于“微服务”.“DevOps”.“Cloud-nat ...

  3. BackgroundWorkerHelper

    public static class BackgroundWorkerHelper { public static void Run(DoWorkEventHandler doWork, RunWo ...

  4. .net程序反编译工具(ILSpy)

    ILSpy是SharpDevelop小组的反编译工具,ILSPY这个开源工具的目的就是代替reflector的,它可以反编译出比reflector更好的C#代码. PC官方版 C#反编译工具ilspy ...

  5. LinkedBlockingQueue与ArrayBlockingQueue

    阻塞队列与普通的队列(LinkedList/ArrayList)相比,支持在向队列中添加元素时,队列的长度已满阻塞当前添加线程,直到队列未满或者等待超时:从队列中获取元素时,队列中元素为空 ,会将获取 ...

  6. js 类型判断

  7. [LeetCode] 204. Count Primes 计数质数

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  8. Harbor密码重置 密码修改 admin密码重置

    Harbor密码重置harbor现在是使用postgresql 数据库了.不再支持mysql,网上有N多重置Mysql密码的,可以略过了.我密码错了默认的Harbor12345 修改为: RedHat ...

  9. [Oracle] Io Error: The Network Adapter could not establish the connection 解决方案

    Io 异常: The Network Adapter could not establish the connection这个异常的出现一般与数据库和你的PC的设置有关 这种异常的出现大致上有下面几种 ...

  10. C语言函数库帮助文档

    C语言函数库帮助文档 安装 1.C语言库函数基本的帮助文档 sudo apt-get install manpages sudo apt-get install manpages-de sudo ap ...