1. 创建bundle,如图,点击 +  ,弹出选择框, macOS 下的Framework & Library  ,点击bundle,输入bundle的名字,然后点击 finish。

 
图1.1
 
图1.2

2. 点击创建好的bundle ,修改属性

 
图2.1
"Base SDK" 设置为 "Latest iOS (iOS 11.2)" (Xcode 9.2为例)
"Build Active Architecture Only" 设置为 "YES"
Installation Directiotory 删除掉后面的路径
Code Signing Identity 选择 Don't Code Sign
"iOS Deployment Target" 设置为 iOS 8.0 (为了兼容性,最好选择最低版本)
"Skip Install" 设置为 "NO"
"Strip Debug Symbols During Copy" 中"Release"模式设置为 "YES"
"IOS Deployment Target" 设置为 "iOS 8.0"
"COMBINE_HIDPI_IMAGES" 设置为 "NO" 

3. 现在开始导入资源,可以导入Xib文件和图片,此处以导入图片为例,点击➕进行添加,如图3.1;或者直接将图片拖入左侧创建的bundle文件夹下,系统会自动导入Copy Bundle Resources里去,如张图3.2所示:

3.1
 
3.2

4. 选择创建的bundle 进行编译,开始生成bundle,分别选择真机和模拟器,然后各运行一遍,即可生成真机和模拟器使用的bundle:

图4.1

5. 找到生成的bundle,打包上架APP的时候应使用真机模式下运行生成的Bundle,即Debug-iPhoneos 文件夹内的bundle。

图5.1

现在已经生成了我们需要的bundle,在项目中直接导入即可使用,

6. 将要使用的bundle集成到项目中后,就可以使用了。需要注意的就是,bundle是静态的,不进行编译的资源文件。所以,要使用bundle中的资源,就需要找到相应的资源路径。

VC获得bundle中的资源

NSString * bundlePath = [[ NSBundle mainBundle] pathForResource: @ "MyBundle"ofType :@ "bundle"];
NSBundle *resourceBundle = [NSBundle bundleWithPath:bundlePath];
UIViewController *vc = [[UIViewController alloc] initWithNibName:@"vc_name"bundle:resourceBundle];

图片获得bundle中的资源

UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 50,50)];
UIImage *image = [UIImage imageNamed:@"MyBundle.bundle/img_collect_success"];
[imgView setImage:image];

或者

UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 50,50)];
NSString *bundlePath = [[ NSBundle mainBundle] pathForResource:@"Test" ofType :@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
NSString *img_path = [bundle pathForResource:imageName ofType:@"png"];
UIImage *image_1=[UIImage imageWithContentsOfFile:img_path];
[imgView setImage:image_1];

当然,可以写成预编译语句:

#define MYBUNDLE_NAME @ "MyBundle.bundle"
#define MYBUNDLE_PATH [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: MYBUNDLE_NAME]
#define MYBUNDLE [NSBundle bundleWithPath: MYBUNDLE_PATH] 

7. 如果将自己打包的bundle给别人使用,别人在打包上传过程中可能会遇到错误提示如:

ERROR ITMS-90171: "Invalid Bundle Structure - The binary file 'lhby.app/Test.bundle/Test' is not permitted. Your app can’t contain standalone executables or libraries, other than a valid CFBundleExecutable of supported bundles. Refer to the Bundle Programming Guide at...

或者

ERROR ITMS-90535: "Unexpected CFBundleExecutable Key. The bundle at 'Payload/dianlan2.app/EaseUIResource.bundle' does not contain a bundle executable. If this bundle intentionally does not contain an executable, consider removing the CFBundleExecutable key from its Info.plist and using a CFBundlePackageType of BNDL. If this bundle is part of a third-party framework, consider contacting the developer of the framework for an update to address this issue."

或者

ERROR ITMS-90034: "Missing or invalid signature. The bundle 'ABC.Test' at bundle path 'Payload/lhby.app/Test.bundle' is not signed using an Apple submission certificate."

网上也有很多的解决办法,这里提供一种解决方法,就是删除bundle里的执行文件:找到工程中的Test.Bundle,右键单击后 选择 "显示包内容",找到里面黑色的可执行文件Test,删除掉,然后找到里面的info.plist文件 ,删除掉Executable file 字段,重新打包,上传应用商店就可以了。

iOS-静态库,动态库,framework,bundle浅析(四)的更多相关文章

  1. ios 开发中 动态库 与静态库的区别

    使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...

  2. 生成lua的静态库.动态库.lua.exe和luac.exe

    前些日子准备学习下关于lua coroutine更为强大的功能,然而发现根据lua 5.1.4版本来运行一段代码的话也会导致 "lua: attempt to yield across me ...

  3. C/C++ 跨平台交叉编译、静态库/动态库编译、MinGW、Cygwin、CodeBlocks使用原理及链接参数选项

    目录 . 引言 . 交叉编译 . Cygwin简介 . 静态库编译及使用 . 动态库编译及使用 . MinGW简介 . CodeBlocks简介 0. 引言 UNIX是一个注册商标,是要满足一大堆条件 ...

  4. linux静态与动态库创建及使用实例

    一,gcc基础语法: 基本语法结构:(由以下四部分组成) gcc -o 可执行文件名 依赖文件集(*.c/*.o) 依赖库文件及其头文件集(由-I或-L与-l指明) gcc 依赖文件集(*.c/*.o ...

  5. Linux 静态库&动态库调用

    1.什么是库在windows平台和linux平台下都大量存在着库.本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执行.由于windows和linux的本质不同,因此二者库的二进制是不 ...

  6. windows库的创建和使用:静态库+动态库

    windows库的创建和使用:静态库+动态库   一.静态库的创建和使用 1. 静态库创建 (1)首先创建projecttest,測试代码例如以下: 1) test.h void test_print ...

  7. Linux中创建和使用静态库&动态库

    库本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执行 Linux下库的种类 linux下的库有两种:静态库和共享库(动态库). 二者的不同点在于代码被载入的时刻不同. 静态库的代码在 ...

  8. C++开发新版本vs使用旧版本vs编译的静态库动态库

    关于vs潜在的升级问题概述 (Visual C++)查看官网的介绍:潜在的升级问题概述 (Visual C++).主要问题: 1. 如果使用 /GL(全程序优化)进行编译,则生成的对象文件只能使用生成 ...

  9. 静态库动态库的编译、链接, binutils工具集, 代码段\数据段\bss段解释

    #1. 如何使用静态库 制作静态库 (1)gcc *.c -c -I../include得到o文件 (2) ar rcs libMyTest.a *.o 将所有.o文件打包为静态库,r将文件插入静态库 ...

  10. iOS 开发新版 动态库framework

    0. 参考 http://www.cocoachina.com/industry/20140613/8810.html framework+xib参考 : http://blog.csdn.net/x ...

随机推荐

  1. 2. RabbitMQ 服务器 之下载安装

    RabbitMQ服务器如何安装? RabbitMQ是一个AMQP(Advanced Message Queue,即高级消息队列协议)服务器 . 下载地址: RabbitMQ下载 安装说明:各平台下Ra ...

  2. Atitti mybatis的单元测试attilax总结

    Atitti mybatis的单元测试attilax总结 版本mybatis 3.2.4 /palmWin/src/main/java/com/attilax/dao/mybatisTest.java ...

  3. Atitit  验证 数字验证 非空验证的最佳算法  h5

    Atitit  验证 数字验证 非空验证的最佳算法  h5 <td><select class="searchBox-select"   style=" ...

  4. [svc]HTTPS证书生成原理和部署细节

    参考: http://www.barretlee.com/blog/2015/10/05/how-to-build-a-https-server/ 今天摸索了下 HTTPS 的证书生成,以及它在 Ng ...

  5. What-does-git-remote-and-origin-mean

    https://www.quora.com/What-does-git-remote-and-origin-mean https://stackoverflow.com/questions/29235 ...

  6. Centos7.x 执行top命令教程

    一.作用 top命令用来显示执行中的进程,使用权限是所有用户 二.格式 top [-] [d delay] [q] [c] [S] [s] [i] [n] 三.命令参数解释 d:指定更新的间隔,以秒计 ...

  7. CLOS网络架构与FATTREE胖树拓扑

    FatTree拓扑结构是由MIT的Fares等人在改进传统树形结构性能的基础上提出的,属于switch-only型拓扑. 整个拓扑网络分为三个层次:自上而下分别为边缘层(edge).汇聚层(aggre ...

  8. [原创]找不到mswinsck.ocx的解决办法

    mswinsck.ocx,是在运行程序或者游戏时,系统弹出错误提示“ 找不到mswinsck.ocx”,或者“ 没有找到 mswinsck.ocx”时,说明您系统中缺失这个OCX文件或者该OCX文件没 ...

  9. SpringBoot------如何将项目打成war包

    1.修改pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:/ ...

  10. 关于删除 hao123 主页设置的一点经验

    :first-child { margin-top: 0px; } blockquote>:last-child { margin-bottom: 0px; } --> 说一说关于删除 h ...