一、创建项目
创建两个项目MyLibDemo 和 MyLib两个项目
建立完成后,文件夹子内情况如下
二、创建workspace
打开Xcode,选择File->New->Workspace
然后把刚才创建的MyLibDemo 和 MyLib拖入workspace中,注意这两个project平级
三、添加Cocoapod管理的第三方库
1、创建Podfile文件,并录入如下内容
platform :ios, '9.3'
# 忽略第三方库所有警告
inhibit_all_warnings!
#指明xcworkspace名称
workspace 'MyLibDemo.xcworkspace'
target 'MyLibDemo' do
project 'MyLibDemo.xcodeproj'
pod 'SVProgressHUD'
end
target 'MyLib' do
#这里的project要指明路径
project 'MyLib/MyLib.xcodeproj'
pod 'SVProgressHUD'
end
2、pod install
四、MyLibDemo的基础配置
这一步的目的是让MyLibDemo项目可以正常调用Cocoapod管理的SVProgressHUD
1、删除SceneDelegate.h/.m文件
2、在AppDelegate.h添加window属性
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow * window;
@end
3、AppDelegate.m中移除两个方法
#pragma mark - UISceneSession lifecycle
//该方法移除
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}
//该方法移除
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
4、在info.plist文件中移除Application Scene Manifest
5、在ViewController.m文件中增加如下代码,并绘制一个button
#import "SVProgressHUD.h"
-(IBAction)clickAction:(id)sender{
[SVProgressHUD showSuccessWithStatus:@"Hello,Demo"];
}
6、运行程序,点击按钮,能正确看到弹窗即为成功。
五、MyLib的基础配置
1、MyLib工程Build Setting配置
把Mach-O Type 设置为Static Library
确认Other Linker Flags 中存在 -ObjC
2、创建HelloObject
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface HelloObject : NSObject
+(void)sayHello;
@end
NS_ASSUME_NONNULL_END
#import "HelloObject.h"
#import "SVProgressHUD.h"
@implementation HelloObject
+(void)sayHello{
[SVProgressHUD showSuccessWithStatus:@"hello,MyLib!!!"];
}
@end
3、设置暴露给外界的头文件
MyLib --> Build Phases --> Headers--> Public
4、修改MyLib.h文件
增加一行引用
#import "HelloObject.h"
六、MyLibDemo去调用MyLib库
1、配置Framework的引用
MyLibDemo --> Build Phases --> Link Binary With Libraries --> 添加MyLib
2、调用Framework中的对象
修改ViewController.m文件内容
#import "ViewController.h"
#import "SVProgressHUD.h"
#import <MyLib/HelloObject.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
-(IBAction)clickAction:(id)sender{
//[SVProgressHUD showSuccessWithStatus:@"Hello,Demo"];
[HelloObject sayHello];
}
@end
3、编译项目,能正常跑起来就说明成功了
七、写在最后
PS:目前我这么编译,用真机测试,最终上传App Store是正常的不需要其他配置的。但其他开发者的资料中还会附带其他的配置。
仅收录,自行尝试。
https://www.jianshu.com/p/f0b7eaa0ab11
这里面记录了:
1、Architectures 编译架构设置
2、真机与模拟器的目标文件合并
3、framework的脚本化打包
4、framework中调用Bundle资源文件
https://www.jianshu.com/p/5392f58dd821
这里面记录了另一种framework静态库依赖Cocoapods第三方库的方式,只有一个project,但我编译起来会有黄色警告,所以没有采用