来源: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. SDM439平台出现部分机型SD卡不能识别mmc1: error -110 whilst initialising SD card【学习笔记】

    SDM439平台出现部分机型SD卡不能识别mmc1: error -110 whilst initialising SD card 打印了如下的log: - ::>[ after ms - :: ...

  2. redis中get值显示为16进制字符串的解决方法

    Linux系统中,通过xshell登录redis,当根据某个key进行get取值时,取到的值为“\xc2\xed\xc0\xad\xcb\xb9\xbc\xd3”格式的十六进制字符串,原因是值中的中文 ...

  3. N以内的素数计算(Java代码)

    列出小于N的所有素数 普通计算方式, 校验每个数字 优化的几处: 判断是否整除时, 除数使用小于自身的平方根的素数 大于3的素数, 都在6的整数倍两侧, 即 6m - 1 和 6m + 1 publi ...

  4. Base64(2)

    import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncoding ...

  5. docker 删除含有指定字符的container

    docker container ls -a|grep 指定字符 | awk '{print $1}'| xargs -I{} docker rm {}

  6. C++使用fill初始化二维数组

    类似如下用法: fill(dis[0], dis[0]+maxn*maxn, INF); 因为 dis[0]才是dis的首元素 dis[0][0] 的地址.

  7. Linux故障排查之CPU占用率过高

    有时候我们可能会遇到CPU一直占用过高的情况.之前我的做法是,直接查找到相关的进程,然后杀死或重启即可.这个方法对于一般的应用问题还不大,但是要是是重要的环境的话,可万万使不得. 如果是重要的环境,那 ...

  8. [LeetCode] 128. Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] 217. Contains Duplicate 包含重复元素

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  10. System.gc()介绍

    System.gc()用于垃圾收集器,调用垃圾收集器将回收未使用的 System.gc()进行回收的准则: 回收没有被任何可达变量指向的对象 JDK实现 public static void gc() ...