iOS架构-静态库.framework之资源文件打包bundle(6)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shifang07/article/details/89452731

iOS架构-静态库.framework手动打包及脚本化打包(5)中介绍了.framework的脚本化打包,虽然在iOS架构-静态库.a打包之资源文件打包成bundle(4)中已经演示过,其实是一样的。但在这里还是补充一下.framework资源文件的使用。以免部分读者心里不甚明白。

1.添加图片资源和带xib的测试类:MyViewController(从iOS架构-静态库.a打包之资源文件打包成bundle(4)的例子的复制来的)
同时也把CRRobotBundleManager 类复制过来,目录如下
在这里插入图片描述3.资源文件的Target Membership只选择bundle

在这里插入图片描述4. 修改代码:将copy 过来的代码中

VideoPlayerLibBundle 替换为 MySDKResource

//重写要加载的view的init方法
- (instancetype)init {
    NSBundle *bundle = [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"MySDKResource.bundle"]];
    self = [super initWithNibName:@"MyViewController" bundle:bundle];
    if (self) {
        // Custom initialization
    }
    return self;
}
    
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    // 方法一
    self.testImageView.image = [UIImage imageNamed:@"MySDKResource.bundle/cr_add_hidden.png"];
    
    // 方法二
    // NSString *pic1Path = [CRRobotBundleManager getFilePathFromBundle:@"cr_add_hidden.png"];
    // self.testImageView.image = [UIImage imageWithContentsOfFile:pic1Path];
}
+ (NSBundle *)getBundle {
    return [NSBundle bundleWithPath: [[NSBundle mainBundle] pathForResource:@"MySDKResource" ofType: @"bundle"]];
}
  1. 选中 Scheme -->MySDKResource.bundle 编译
    在这里插入图片描述
  2. 编译后的MySDKResource.bundle 的位置
    在这里插入图片描述
  3. 在脚本中将MySDKResource.bundle 拷贝到 MySDK 文件中
    在脚本 Script.sh lipo -create 步骤上面添加如下代码
#bundle工程名
bundle_name=${project_name}Resource
#图片资源资源
BUNDLE_DIR_INCLUDE=${build_DIR}/${development_mode}-iphoneos/${bundle_name}.bundle
echo "图片资源资源路径=${BUNDLE_DIR_INCLUDE}"
#将图片资源copy到目标文件夹
cp -R "${BUNDLE_DIR_INCLUDE}" "${INSTALL_DIR}"
  1. 然后重新执行脚本即可得到目标文件夹
    在这里插入图片描述
  2. 导入demo使用
    在这里插入图片描述
  3. 跳转加载 framework 使用bundle 的资源效果如下:
    在这里插入图片描述

终于加载出来的。

写在最后:静态库.framework 以及 资源bundle 手动、脚本自动打包以及使用到此结束了。

接下来课题还没准备好,不过还是在架构,静态库或者动态库,以及脚本、cocoapods打包库 以及依赖第三方库方面继续研究!

猜你喜欢

转载自blog.csdn.net/shifang07/article/details/89452731