来源: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. Fabric.js canvas 图形库

    1.github地址: https://github.com/fabricjs/fabric.js 2.简述 Fabric.js将canvas的编程变得简单.同时在canvas上添加了交互.交互包括: ...

  2. VMware7.1安装教程

    VMWare是一个"虚拟PC"软件公司.它的产品可以使你在一台机器上同时运行二个或更多Windows.DOS.LINUX系 统.与"多启动"系统相比,VMWar ...

  3. WebGL调试工具分享

    学习WebGL,我们需要一些好用的调试工具,下面分享3个常用的调试工具. WebGL Inspector 下载地址:https://github.com/benvanik/WebGL-Inspecto ...

  4. ROS tf-深入Time和TF

    博客转载自:https://www.ncnynl.com/archives/201702/1313.html ROS与C++入门教程-tf-深入Time和TF 说明: 介绍使用waitForTrans ...

  5. QT中常用工具总结

    1.qmake 利用.pro文件生成Makefile 命令为: eg: qmake -o Makefile hello.pro 2. uic 利用ui界面审查.h头文件 命令为: eg: uic go ...

  6. 查询、下载GWAS目录数据的R包(gwasrapidd)

    目前GWAS方向发了很多文献,但是并没有一个很完善的R包对这些文献的数据进行汇总. 接下来推荐的这个是最新发表的GWAS数据汇总R包​.看了一下功能齐全,但是数据不是收录的很齐全​. 下面具体讲一下. ...

  7. oracle 存储函数,更新库存

    create procedure PRO_update_Goods_group_stock is v_min_stock , ); v_gg_stock , ); v_goods_no number; ...

  8. JAVA克隆对象报错:The method clone() from the type Object is not visible

    将一个对象复制一份,称为对象的克隆技术.在Object类汇总存在一个clone()方法:protected Onject clone() throws CloneNotSupportedExcepti ...

  9. 学习记录-java基础部分(一)

    学习记录-java基础部分(一) 参考:GitHub上的知名项目:javaGuide : https://github.com/Snailclimb/JavaGuide/blob/master/doc ...

  10. NGINX安全配置和限制访问

    说起网络攻击,可能很多人只知道大名鼎鼎的DDOS攻击,这种攻击廉价且效果出众,直接通过第四层网络协议用他的带宽把你的带宽顶掉,造成网路阻塞,防不胜防,就连腾讯这种大鳄公司也被大流量DDOS搞过焦头烂额 ...