Framework调试与打包

2018-10-31  本文已影响0人  莱怯兜特

一.Framework调试

Framework无法单独进行调试,需要依赖于项目进行调试

增加一个Target,选择Single View App即可

image.png

在APP应用中,导入framework的头文件,即可直接调用SDK功能并进行调试

image.png

将framework中的.m文件,添加至app Target的资源中

image.png

增加了APP后,会存在2个target,调试运行时选择app的target进行运行

二.Framework打包

target选择至sdk后,直接进行编译即可
编译后找到Products - DemoSDK.framework - show in finder 就可找到framework包了

image.png

三.Framework整合

编译时的device若选择真机,则framework包仅可供真机使用
若选择模拟器,则framework包仅可供模拟器使用
因此需要将2个framework包进行整合

找到2个framework中的进制文件的路径


image.png

终端输入命令如下
lipo -create 路径1 路径2 -output 输出路径

最后将输出后的进制文件替换framework包里的就行了

四.Framework中的图片,xib及资源文件打包

1.概述

当SDK集成进别人项目中时,图片及xib及资源文件并不直接存在于别人的mainbundle中
因此当SDK中用到图片,xib及资源文件时,可以创建一个用于存放资源的专属bundle

在使用者集成时,同时导入framework及资源bundle即可

image.png
2.创建bundle
image.png
3.配置bundle的BuildSetting

Base SDK - Latest ios (ios 11.4) (让其在Ios上生效)
Build Active Architecture Only - NO (所有设备生效)
ios Developyment Target - ios 8.0 (让其能够支持ios8.0)
Enable Bitcode - NO (bundle里不是代码,不能支持bitcode)

4.资源放入bundle中
image.png
5.调用Bundle中的xib

创建带有xib的VC时,需要从特定bundle中来取出xib
同时,在调试时要切换回以前的方式
图片也是一样,下面是代码

+(void)showSDKXib{
    NSLog(@"SDK Running");
    //正式包
    AMDemoSDKVC* demoVC = [[AMDemoSDKVC alloc]initWithNibName:[self nibName:@"AMDemoSDKVC.xib"] bundle:nil];
    
    //测试包
    //AMDemoSDKVC* demoVC = [[AMDemoSDKVC alloc]initWithNibName:@"AMDemoSDKVC" bundle:[NSBundle mainBundle]];
    
    
    [[self topViewController] presentViewController:demoVC animated:YES completion:nil];
}


+(NSString*)nibName:(NSString*)name{
    //正式包
    return [NSString stringWithFormat:@"DemoSDKBundle.bundle/%@",name];
}

+(UIImage*)imageName:(NSString*)imagename{
    //正式包
    NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"DemoSDKBundle" withExtension:@"bundle"]];
    UIImage *image = [UIImage imageNamed:imagename inBundle:bundle compatibleWithTraitCollection:nil];
    return image;
}

+(UITableViewCell*)cellForNibName:(NSString*)nibName{
    //正式包
    NSString *strResourcesBundle = [[NSBundle mainBundle] pathForResource:@"DemoSDKBundle" ofType:@"bundle"];
    NSBundle* bundle = [NSBundle bundleWithPath:strResourcesBundle];
    return [[bundle loadNibNamed:nibName owner:self options:nil]lastObject];
}
6.bundle打包

target选择bundle,build一下即可。不需要进行合并

上一篇 下一篇

猜你喜欢

热点阅读