研究两天终于研究完了-分享给大家
如何把整个项目打包SDK?,为什要怎这么麻烦的打包成SDK呢?只可意会不可言传!
一、创建iOS- Framework(参数设置)
1、选择Build Settings 参数 mach-o 设置为 static library 静态库(否则不能通过审核)
2、选择Build Settings 参数 Build Active Architeture only 改为NO
3、选择Build Settings 参数 ENABLE_BITCODE 改为NO
4、设置Build Settings 参数 在Architectures下增加armv7s
5、设置Build Settings 参数 Dead Code Stripping设置为NO
6、设置Build Settings 参数 Strip Debug Symbol During Copy 全部设置为NO
7、设置Build Settings 参数 Strip Style设置为Non-Global Symbols
8、设置Build Settings 参数 Base SDK >> Latest iOS(iOS 选择最新的)
9、TestSDK.h(必须是公开的,否则无法引用)中将所有要公开的.h引入
10、把用到的文件及文件夹拖到里面,将需要公开的头文件放到Public里
注意:如果用到第三方库建议cocoapods 添加,打包后不用加入第三方库, 只需要在使用sdk的项目加入cocoapods添加相同的库就可以了!
二、创建bundle打包资源文件(放入所有资源文件Xib、Image、GIF、media、html等)
1、选择Build Settings 参数 ENABLE_BITCODE 改为NO
2、选择Build Settings 参数 Base SDK 改为IOS
3、选择Build Settings 参数 iOS Deployment Target改为 ios 9.0(最低版本)
4、选择Build Settings 参数 COMBINE_HIDPI_IMAGES 设置为NO
5、注意xib打包后为二进制nib文件
6、xib中使用的图片需要带后缀名比如xxx.png
7、只能用Xcode创建bundle否则xib无法显示图片
三、修改代码
1、所有加载的资源文件从bundle中加载
#define SDKBundlePath [[NSBundle mainBundle] pathForResource:@"TextSDKResources" ofType:@"bundle"]
#define SDKBundle [NSBundle bundleWithPath:SDKBundlePath]
#define SDKImage(imageName) [SDKBundlePath stringByAppendingPathComponent:imageName]
2、如果有XIB需要在init的时候加载nib文件
四、编译
1、选择xxxSDK 的tag command + b 编译代码
2、选择xxxBundle 的tag command + b 编译资源文件
五、sdk的使用
1、把xxxSDK和xxxBundle分别拖入项目中AppDelegate相同的路径,否则可能会报错
2、在AppDelegate中导入后直接加载SDK 就可以了
3、删除bundle里的执行文件:找到工程中的xxx.Bundle,右键单击后 选择 "显示包内容",找到里面黑色的可执行文件xxx,删除掉 否者上传商店会报错 ERROR ITMS-90166 ERROR ITMS-90171
4、找到framework与bundle里面的info.plist文件 ,删除掉Executable file 字段,否者上传商店会报错 ERROR ITMS-90166 ERROR ITMS-90171
#import "TextSDK.framework/Headers/TextSDK.h"
@interface AppDelegate ()
@end
@implementation
AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[TextSDK configWithAppDelegate:self Application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}