NSBundle *mainBundle将hex文件放入app资源库
来源:互联网 发布:大话数据挖掘 编辑:程序博客网 时间:2024/05/21 15:04
首先将hex文件放到工程文件中,在object-C升级的线程中使用NSBundle *mainBundle将hex文件复制到app的资源库中,所在的位置为:app-显示包内容-Contents-Resources,在.cpp中写一个函数将object-C绑定的路径传到.cpp中,因为在.cpp中升级及读取hex版本号时也需要这个路径。这样不管用户将app放在哪个文件夹下,在读取的时候都会去app所在的资源库中去读取hex文件。
用到的函数及定义:
char GetNativePath[300];//数组中存放的是hex文件的路径
char *apGetNativePath =GetNativePath;
constchar *HMDhexpath;//Object-C中绑定到资源库的hex文件路径
void GetHexPath(constchar *str){
HMDhexpath = str;
}
方法1:将hex路径转化成URL,再将URL转为NSString,再将NSString转为char,这种转化后路径会比真实路径多7个字符,file://+真实路径,在将这个路径传给GetNativePath数组(总长度为300)时需要将这前七个字符截取掉
strncpy(GetNativePath,HMDhexpath+7, 280);//方法1
路径:file:///Users/Develop/Library/Developer/Xcode/DerivedData/XXXcqyacwywhttktwcrchmqhlpkohky/Build/Products/Debug/XXX.app/Contents/Resources/DIS01_STMF205_HMD_APP.hex
NSURL*pathUrl = [[NSBundle mainBundle]URLForResource:@"DIS01_STMF205_HMD_APP" withExtension:@"hex"subdirectory:nil];
NSString*urlStr = pathUrl.absoluteString;
constchar *hexpath = [urlStrcStringUsingEncoding:NSUTF8StringEncoding];//转化出来只能是const类型
GetHexPath(hexpath);//将绑定hexpath路径通GetHexPath传到.cpp文件中去
方法2:hexpath为真实路径,直接传给GetNativePath,无需截取
strncpy(GetNativePath,HMDhexpath, 300);//方法2
路径: /Users/Develop/Library/Developer/Xcode/DerivedData/XXXcqyacwywhttktwcrchmqhlpkohky/Build/Products/Debug/XXX.app/Contents/Resources/DIS01_STMF205_HMD_APP.hex
*/
NSBundle*mainBundle = [NSBundlemainBundle];
NSString*imagePath = [mainBundle pathForResource:@"DIS01_STMF205_HMD_APP"ofType:@"hex"];
constchar *hexpath = [imagePathcStringUsingEncoding:NSUTF8StringEncoding];//转化出来只能是const类型
GetHexPath(hexpath);
GetHexPath是.cpp中的函数,在object-C中将生成的路径传给了HMDhexpath这个指针- NSBundle *mainBundle将hex文件放入app资源库
- [NSBundle mainBundle]加载文件用法
- 拷贝 xxx.app [NSBundle mainBundle] 包里的文件到 Documents 目录下
- NSBundle、[NSBundle mainBundle] 详解
- XCode ios iphone 资源文件管理 NSBundle mainBundle
- [NSBundle mainBundle] 详解
- NSBundle以及mainBundle
- [[NSBundle mainBundle] infoDictionary]
- [NSBundle mainBundle] 详解
- NSBundle mainBundle
- [[NSBundle mainBundle] infoDictionary]
- [[NSBundle mainBundle] infoDictionary]
- 深入理解 [NSBundle mainBundle]
- [NSBundle mainBundle] 详解
- NSBundle MainBundle的路径
- [NSBundle mainBundle] infoDictionary
- 获取版本号[[NSBundle mainBundle] infoDictionary]
- 获取版本号[[NSBundle mainBundle] infoDictionary]
- mybats 操作符
- windows 下日志查看工具
- 关于ASP.NET MediaPlayer服务器控件及ie11中silverlight相关问题
- Art Generation with Neural Style Transfer
- HTTPS客户端java实现
- NSBundle *mainBundle将hex文件放入app资源库
- 最新的 iscroll5 下拉刷新上拉加载以及 首次加载内容不足时的下拉上拉补充
- autoEncoder
- shell环境变量
- RxJava2二刷
- 11.26 WC模拟总结&题解
- type-c插口,什么意思?
- 大数据下 移动计算 和 移动数据的一点理解
- c++命名空间