此功能的方便之处就是framework的源码添加到主工程中,修改framework的代码之后可以直接测试相关功能,不需要编译framework然后再添加到另外一个工程中测试。内嵌方式如下:
1、新建一个主工程名为UseFrameworkProject,然后将framework的工程文件.xcodeproj直接拖拽到文件夹下,如下图:
2、将framework工程下Products目录下的.framework文件拖入主工程的Link Binary With Libraries,如下:
此时就可以在主工程的文件中调用framework对外公开的api了,只需#import <APPBaseSDK/APPBaseSDK.h>引入framework的头文件即可。
二、新建bundle
如果framework中添加图片和xib资源,需要将这些资源放到bundle中,然后供其它工程调用。此文的bundle是基于上面的内嵌工程创建的,步骤如下:
点击next之后,命名即可。
2、修改bundle的相关配置:
Base SDK --->iOS
iOS Deployment Target ---> 9.0
COMBINE_HIDPI_IMAGES--->NO,否则图片格式变成了.tiff
enable bitcode ----> NO
3、向bundle中添加资源,target bundle --》build Phases --》copy bundle resources --》+,添加图片和xib资源。
4、编译bundle,选择bundle和相关设备后编译即可,编译成功的话,products文件夹下的.bundle文件会变成黑色,否则是红色。
5、主工程调用bundle,主工程的target--》build Phases --》copy bundle resources --》+,选择framework的bundle文件(新建的bundle文件)即可。
调用方式一:
self.imgView.image = [UIImage imageNamed:@"APPBaseSDKBundle.bundle/image1.jpg"];
调用方式二:
NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"APPBaseSDKBundle" withExtension:@"bundle"]];
self.imgView.image = [UIImage imageNamed:@"image1.jpg" inBundle:bundle compatibleWithTraitCollection:nil];
或
TestViewController *controller = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:bundle];
6、主工程嵌套framework的情况下,只要编译主工程,framework的修改会立即编译,但是怎样做到bundle也同时被编译呢?方法如下:
给framework添加工程依赖,target framework ---》build Phases ---》Target Dependencies --》 +,选择bundle即可。