[AIR] NativeExtension在IOS下的开发实例 --- IOS项目的创建 (一)
来源: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。其他的代码都是必需的。
- #import "FlashRuntimeExtensions.h"
- #import <AudioToolbox/AudioServices.h>
- #import <UIKit/UIKit.h>
- FREObject ShowIconBadageNumber(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
- int32_t t;
- FREGetObjectAsInt32(argv[0], &t);
- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:t];
- return argv[0];
- }
- // InitNativeCode()
- //
- // An InitNativeCode function is necessary in the Android implementation of this extension.
- // Therefore, an analogous function is necessary in the iOS implementation to make
- // the ActionScript interface identical for all implementations.
- // However, the iOS implementation has nothing to do.
- //此方法参考Adobe的官方例子,Vibration的。具体不明白的可以看注释。
- FREObject InitNativeCode(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
- NSLog(@"Entering InitNativeCode()");
- // Nothing to do.
- NSLog(@"Exiting InitNativeCode()");
- return NULL;
- }
- // ContextInitializer()
- //
- // The context initializer is called when the runtime creates the extension context instance.
- void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
- uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) {
- NSLog(@"Entering ContextInitializer()");
- *numFunctionsToTest = 2;
- //这地方 ,如果是两个方法有两个2,如果是三个方法就是3了。当然你可以自己看着定义了。
- FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * 2);
- //这地方定义方法名
- //Just for consistency with Android
- func[0].name = (const uint8_t*) "initNativeCode";
- func[0].functionData = NULL;
- func[0].function = &InitNativeCode;
- //这地方定义方法名
- func[1].name = (const uint8_t*) "ShowIconBadageNumber";
- func[1].functionData = NULL;
- func[1].function = &ShowIconBadageNumber;
- *functionsToSet = func;
- NSLog(@"Exiting ContextInitializer()");
- }
- // ContextFinalizer()
- //
- // The context finalizer is called when the extension's ActionScript code
- // calls the ExtensionContext instance's dispose() method.
- // If the AIR runtime garbage collector disposes of the ExtensionContext instance, the runtime also calls
- // ContextFinalizer().
- void ContextFinalizer(FREContext ctx) {
- NSLog(@"Entering ContextFinalizer()");
- // Nothing to clean up.
- NSLog(@"Exiting ContextFinalizer()");
- return;
- }
- // ExtInitializer()
- //
- // The extension initializer is called the first time the ActionScript side of the extension
- // calls ExtensionContext.createExtensionContext() for any context.
- void ExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
- FREContextFinalizer* ctxFinalizerToSet) {
- NSLog(@"Entering ExtInitializer()");
- *extDataToSet = NULL;
- *ctxInitializerToSet = &ContextInitializer;
- *ctxFinalizerToSet = &ContextFinalizer;
- NSLog(@"Exiting ExtInitializer()");
- }
- // ExtFinalizer()
- //
- // The extension finalizer is called when the runtime unloads the extension. However, it is not always called.
- void ExtFinalizer(void* extData) {
- NSLog(@"Entering ExtFinalizer()");
- // Nothing to clean up.
- NSLog(@"Exiting ExtFinalizer()");
- return;
- }
复制代码
5,Build项目,会在项目文件夹Products生成一个.a 的文件,复制出来,我们在打包ANE的时候要用。
好了。IOS项目创建完毕。下一篇介绍如果创建ActionScript Library。
项目源文件下载在第四篇
[AIR] NativeExtension在IOS下的开发实例 --- IOS项目的创建 (一)的更多相关文章
- [AIR] NativeExtension在IOS下的开发实例 --- 新建项目测试ANE(四)
来源:http://bbs.9ria.com/thread-102043-1-1.html 通过前面的努力,好了,我们终于得到了一个ANE文件了.下面我们开始新建一个Flex Mobile项目做一下测 ...
- [AIR] NativeExtension在IOS下的开发实例 --- Flex库项目的创建(二)
来源:http://bbs.9ria.com/thread-102038-1-1.html 上一章,我已经介绍了如果创建IOS库文件,并定义了两个方法ShowIconBadageNumber和Init ...
- [AIR] NativeExtension在IOS下的开发实例 --- ANE文件的打包(三)
来源:http://bbs.9ria.com/thread-102041-1-1.html 好了,前面的准备工作做的差不多了.此时我们应用有下面几个文件:extension.xml CoolEx ...
- iOS下OpenCV开发用OC还是Swift
本文为作者原创,转载请注明出处(http://www.cnblogs.com/mar-q/)by 负赑屃 其实标题中这个问题并不准确,准确的说法应该是iOS下的OpenCV开发是使用OC还是Swift ...
- iOS下OpenCV开发配置的两个常见问题(sign和link)
本文为作者原创,转载请注明出处(http://www.cnblogs.com/mar-q/)by 负赑屃 先上可以运行官方推荐的<OpenCV for iOS samples>的demo链 ...
- Android studio 下 JNI 开发实例
在AS中进行 NDK 开发之前,我们先来简单的介绍几个大家都容易搞懵的概念: 到底什么是JNI,什么是NDK? 何为“交叉编译”? 先看什么是 JNI?JNI 的全称就是 Java Native In ...
- AJ学IOS 之ipad开发qq空间项目横竖屏幕适配
AJ分享,必须精品 一:效果图 先看效果 二:结构图 如图所示: 其中用到了UIView+extension分类 Masonry第三方框架做子控制器的适配 NYHomeViewController对应 ...
- iOS下的WiFi开发
iOS下Wi-Fi开发需要添加依赖库SystemConfiguration.framework,在需要使用Wi-Fi信息的控制器下引入头文件#import <SystemConfiguratio ...
- 移动端底部fixed固定定位输入框ios下不兼容
简短记录下最近开发移动端项目碰到的小坑,产品需求做一个售后对话页面,底部固定输入框,和微信对话差不多,但是在ios下,fixed失效,输入框被虚拟键盘挡住,在安卓下是正常的. 尝试过网上说的很多方法, ...
随机推荐
- SDM439平台出现部分机型SD卡不能识别mmc1: error -110 whilst initialising SD card【学习笔记】
SDM439平台出现部分机型SD卡不能识别mmc1: error -110 whilst initialising SD card 打印了如下的log: - ::>[ after ms - :: ...
- redis中get值显示为16进制字符串的解决方法
Linux系统中,通过xshell登录redis,当根据某个key进行get取值时,取到的值为“\xc2\xed\xc0\xad\xcb\xb9\xbc\xd3”格式的十六进制字符串,原因是值中的中文 ...
- N以内的素数计算(Java代码)
列出小于N的所有素数 普通计算方式, 校验每个数字 优化的几处: 判断是否整除时, 除数使用小于自身的平方根的素数 大于3的素数, 都在6的整数倍两侧, 即 6m - 1 和 6m + 1 publi ...
- Base64(2)
import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncoding ...
- docker 删除含有指定字符的container
docker container ls -a|grep 指定字符 | awk '{print $1}'| xargs -I{} docker rm {}
- C++使用fill初始化二维数组
类似如下用法: fill(dis[0], dis[0]+maxn*maxn, INF); 因为 dis[0]才是dis的首元素 dis[0][0] 的地址.
- Linux故障排查之CPU占用率过高
有时候我们可能会遇到CPU一直占用过高的情况.之前我的做法是,直接查找到相关的进程,然后杀死或重启即可.这个方法对于一般的应用问题还不大,但是要是是重要的环境的话,可万万使不得. 如果是重要的环境,那 ...
- [LeetCode] 128. Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] 217. Contains Duplicate 包含重复元素
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- System.gc()介绍
System.gc()用于垃圾收集器,调用垃圾收集器将回收未使用的 System.gc()进行回收的准则: 回收没有被任何可达变量指向的对象 JDK实现 public static void gc() ...