iOS使用.a类型的静态库

简介: 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)。

目录
相关文章
|
1月前
|
iOS开发
iOS使用.framework类型的静态库
iOS使用.framework类型的静态库
25 1
|
1月前
|
开发工具 iOS开发
iOS制作.framework静态库
iOS制作.framework静态库
28 1
|
1月前
|
开发工具 iOS开发
iOS制作.a类型的静态库
iOS制作.a类型的静态库
27 1
|
1月前
|
开发工具 iOS开发 Perl
iOS使用SDK静态库
iOS使用SDK静态库
23 0
|
监控 开发者 iOS开发
iOS第三方网络诊断库——LDNetDiagnoService
iOS第三方网络诊断库——LDNetDiagnoService
512 0
|
1天前
|
iOS开发 开发者 容器
探索iOS开发中的SwiftUI框架
【6月更文挑战第21天】本文深入探讨了苹果在iOS开发中推出的SwiftUI框架,旨在为开发者提供一种声明式、更简洁的界面设计方法。文章首先概述了SwiftUI的核心概念和优势,接着通过一个天气预报应用实例,详细讲解了如何使用SwiftUI进行布局和用户界面的设计。此外,还讨论了SwiftUI与UIKit的差异,以及如何将SwiftUI集成到现有的项目中。最后,文章展望了SwiftUI的未来发展方向,包括潜在的改进和新特性。
|
1天前
|
Java 开发工具 Android开发
安卓与iOS开发差异解析
【6月更文挑战第21天】本文旨在深入探讨安卓和iOS两大移动操作系统在应用开发过程中的主要差异。通过对比分析,揭示各自的设计哲学、编程语言选择、用户界面构建、性能优化策略以及发布流程的异同。文章将提供开发者视角下的实用信息,帮助他们更好地理解各自平台的特点和挑战,从而做出更明智的开发决策。
|
2天前
|
Java 开发工具 Android开发
探索安卓与iOS开发的核心差异
【6月更文挑战第20天】在移动应用开发的广阔天地中,安卓和iOS两大平台各自占据半壁江山。本文将深入探讨这两大操作系统在开发过程中的主要区别,包括编程语言、开发工具、用户界面设计哲学、系统架构以及市场分布等方面。通过对这些关键差异的分析,旨在为开发者提供一份实用的指南,帮助他们在面对项目决策时,能够更加明智地选择合适的平台,并针对特定平台优化他们的应用。
|
2天前
|
开发工具 Android开发 iOS开发
探索安卓与iOS开发的差异:从工具到用户体验
【6月更文挑战第20天】在移动应用开发的广阔天地中,安卓和iOS两大平台各自占据半壁江山。本文将深入探讨这两个操作系统在开发环境、编程语言、用户界面设计以及性能优化等方面的关键差异。我们将通过比较分析,揭示各自平台的独特优势和面临的挑战,为开发者提供决策参考,并为最终用户提供更深层次的用户体验洞察。
|
4天前
|
Java Android开发 Swift
探索Android与iOS开发的差异:平台选择对项目成功的影响
【6月更文挑战第18天】在移动应用开发的广阔天地中,Android和iOS两大平台各据一方,它们在市场份额、用户群体及开发环境上各有千秋。本文将深入分析这两个操作系统的开发差异,探讨如何根据项目需求选择合适的平台,并讨论跨平台解决方案的可行性与挑战。我们将通过实际案例,揭示平台选择对项目成功的关键性影响,为开发者提供决策支持。