http://note.youdao.com/s/FIrWDcun
记录一下由简单到复杂SDK的制作过程
创建项目如图所示
https://juejin.cn/post/6844903860968882190 参考文档
工程创建成功后,配置SDK支持的最低版本,如下图所示
创建一个类文件,如图所示,
接下来配置一下其他内容
1、设置Build Setting参数 将Build Active Architecture only设置为NO
2、设置Build Setting参数 在Architectures下增加armv7s
3、设置Build Setting参数 Mach-O Type 为Static Library (配置静态、动态)
4、在Build Phases中设置需要公开和需要隐藏的头文件,将.h文件移动到 Public 中
5、将要暴露的 .h 文件引入到创建工程时生成的 .h 文件中,不进行该操作步骤会出现错误,下面会给出错误提示,此时引入成功之后,可以编译,生成 SDK,将 SDK 引入工程就可以使用这个类了
6、 编译之后,将 SDK 导入需要的项目工程就可以使用了 下面就运行成功。
注意:第五步骤,如果我们不在创建项目时生成的.h文件引入我们暴露的.h文件。会出现下面提醒提示,如如:Missing submodule ‘’
上面只是简单的 SDK 制作,我们还有很多复杂的 SDK 项目中有很多业务处理,需要依赖或者引入很多第三方库,继承还有很多注意事项,下面针对分类方法无法调用 bug 进行解答
SDK 引入如下分类文件,使用.h 里面的属性会报错
-[UIView width]: unrecognized selector sent to instance 0x100614350
报错如图: -[UIView width]: unrecognized selector sent to instance 0x100614350
解决方法:Other linker flags 设置的值实际上就是ld命令执行时后面所加的参数,主要有-ObjC - -force_load 等
https://blog.csdn.net/lfdanding/article/details/102836692 分类方法无法使用
配置图如下:
制作 SDK 的工程使用Cocopoad引入依赖库的编译会出现如图错误信息:MJRefresh.framework: No such file or directory ,解决方法
ios开发之–libtool: can’t locate file for: -lPods-xxx
https://www.cnblogs.com/hero11223/p/12785197.html
删除 Frameworks 里的文件, comnd+B 即可。
在Xcode12.4 创建的新项目含有 SceneDelegate 分类,此时如果添加 UINavigationController 导航栏在代理方法中,编译出错,错误信息是: Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[SceneDelegate window]: unrecognized selector sent to instance 0x2833688d0’
terminating with uncaught exception of type NSException
https://www.cnblogs.com/jiduoduo/p/12671504.html
解决方法:在AppDelegate 的.h中添加 @property (nonatomic, strong) UIWindow * window; 进行编译即可
参考文档 https://www.cnblogs.com/jiduoduo/p/12671504.html
适配 ios 13以上和以下 AppDelegate 和 SceneDelegate 的导航栏跳转设置
AppDelegate .h和.m 设置
// self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
// self.window.rootViewController = [[UITabBarController alloc]init];
// self.window.backgroundColor = [UIColor whiteColor];
// [self.window makeKeyAndVisible];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ViewController *vc1 = [[ViewController alloc] init];
UINavigationController * vc = [[UINavigationController alloc]initWithRootViewController:vc1];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
SceneDelegate 的 .h 和 .m 设置
if (@available(iOS 13.0, *)) {
if ([scene isKindOfClass:[UIWindowScene class]]) {
UIWindowScene * windowScence =(UIWindowScene*)scene;
UIWindow * window = [[UIWindow alloc]initWithWindowScene:windowScence];
window.backgroundColor = [UIColor clearColor];
UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:[ViewController new]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
}
} else {
}
适配模拟器和真机的 framework (合并两个frameWork)
xcode 的模拟器添加了arm64 在合并frameSdk 的时候会出现错误
https://www.jianshu.com/p/c61a2512fb81 解决方法