iOS frameWork SDK制作 笔记

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 解决方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值