.bundle文件的打包及使用

1. 创建bundle 如图所示:

bundle1.png

2. 修改配置

(1.)"Base SDK" 设置为 "Latest iOS (iOS 11.2)" (Xcode 9.2为例)

     "Build Active Architecture Only" 设置为 "YES"
bundle2.png

(2.)Installation Directiotory 删除掉后面的路径


bundle3.png

(3.)Code Signing Identity 选择 Don't Code Sign


bundle6.png

(4.)"iOS Deployment Target" 设置为 iOS 8.0 (为了兼容性,最好选择最低版本)


bundle9.png

(5.)"Skip Install" 设置为 "NO"


bundle5.png

(6.)"Strip Debug Symbols During Copy" 中"Release"模式设置为 "YES"


bundle8.png

(7.) "COMBINE_HIDPI_IMAGES" 设置为 "NO"


bundle7.png

3. 现在开始导入图片资源

(1.直接拖项目中,系统会自动导入Copy Bundle Resources里去,2.如下图加进去)


bundle1.png

4. 生成 bundle

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


bundle2.png

5. 打包 bundle

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


bundle3.png

6.bundle的使用

因为bundle是静态的,不进行编译的资源文件。所以,要使用bundle中的资源,就需要找到相应的资源路径。

(第一种方法)
 
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 50,50)];
 
UIImage *image = [UIImage imageNamed:@"Image.bundle/Add.png"];
 
[imgView setImage:image];

(第二种方法)
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 50,50)];
 
NSString *bundlePath = [[ NSBundle mainBundle] pathForResource:@"Image" ofType :@"bundle"];
 
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
 
NSString *imgPath = [bundle pathForResource:Add ofType:@"png"];
 
UIImage *image=[UIImage imageWithContentsOfFile: imgPath];
 
[imgView setImage:image];

注:打包的bundle给别人使用,别人在打包完上传过程中可能会极大的坑
20181101205618916.png
20181101205639480.png
20181101205655298.png

有很多解决办法,我用的是最简单的办法:

就是删除bundle里的执行文件:找到工程中的Image.Bundle,右键单击后 选择 "显示包内容",找到里面的info.plist文件 ,删除掉Executable file 字段,重新打包,上传应用商店就可以了。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容