iOS使用.a类型的静态库

iOS使用.a类型的静态库
1.新建一个新工程
2.引入SDKDemoBundle.bundle资源文件
注意:不过SDKDemoBundle.bundle资源文件并不被编译进.a文件,只是以后找SDKDemoBundle.bundle资源文件方便。可以通过比较添加和删除SDKDemoBundle.bundle资源文件生成的libSDKStaticDemo.a大小知道他们一样大。
当然也可以参考如何访问组件的bundle资源来使用.bundle资源。
3.引入 include 文件
在之前的静态库文件找到任意的生成文件 引入 include 文件。
由于它要把生成的库中的include 文件加载到项目中,这样拷贝文件夹也确实没有Framework库方便。
在这里插入图片描述
4.引入libSDKStaticDemo-Debug.和libSDKStaticDemo-Release.a
最后引入结果如下
在这里插入图片描述
5.检查Linked Frameworks and Libraries下是否有你的静态库,若没有会crash。不过默认是会在它下面看到的。当然你用pods导入的在工程的Linked Frameworks and Libraries看不到,不过不影响你的正确使用。这个和动态库需要你手动配置到Embedded Binaries下简单了,真正达到傻瓜式使用。当然更简单的是做一个公有组件
6.增加资源文件SDKDemoBundle.bundle,不增加资源文件,而使用资源文件会crash.
7.增加使用动态库的代码。
ViewController.m

#import "ViewController.h"
#import "SDKDemoViewController.h"
#import "TestTool.h"

@interface ViewController ()
@property (nonatomic, strong) UIButton *testBtn;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIButton *testBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 100, 50, 50)];
    [testBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [testBtn setTitle:@"测试" forState:UIControlStateNormal];
    [testBtn addTarget:self action:@selector(testAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:testBtn];
    testBtn.center = self.view.center;
    self.testBtn = testBtn;
}

- (void)testAction:(UIButton *)button
{
    [TestTool testLog];
    SDKDemoViewController *vc = [[SDKDemoViewController alloc] init];
    [self presentViewController:vc animated:YES completion:nil];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [self.view bringSubviewToFront:self.testBtn];
}

@end

8.修改环境
在这里插入图片描述
在这里插入图片描述
修改采用debug模式运行libSDKStaticDemo-Debug.a后面出现R标志,libSDKStaticDemo-Release.a显示A。
反之亦然。
在这里插入图片描述
8.调用以及结果
在这里插入图片描述
9.执行pod update --verbose --no-repo-update下载依赖库报错

[!] The Podfile contains framework or static library targets (ELockSDK), for which the Podfile does not contain host targets (targets which embed the framework).
If this project is for doing framework development, you can ignore this message. Otherwise, add a target to the Podfile that embeds these frameworks to make this message go away (e.g. a test target).

[!] 'Bugly' uses the unencrypted http protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts in there. Please reach out to the library author to notify them of this security issue.

[!] 'UMengUShare' uses the unencrypted http protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts in there. Please reach out to the library author to notify them of this security issue.

[!] The `ELockSDK [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-ELockSDK/Pods-ELockSDK.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

解决方案:
按照下图设置工程的配置中,搜索OTHER_LDFLAGS,在第一行增加$(inherited)
在这里插入图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值