一、創(chuàng)建項(xiàng)目
創(chuàng)建兩個(gè)項(xiàng)目MyLibDemo 和 MyLib兩個(gè)項(xiàng)目
建立完成后意蛀,文件夾子內(nèi)情況如下
二蛉签、創(chuàng)建workspace
打開Xcode悯嗓,選擇File->New->Workspace
然后把剛才創(chuàng)建的MyLibDemo 和 MyLib拖入workspace中,注意這兩個(gè)project平級(jí)
三骚秦、添加Cocoapod管理的第三方庫
1她倘、創(chuàng)建Podfile文件,并錄入如下內(nèi)容
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的基礎(chǔ)配置
這一步的目的是讓MyLibDemo項(xiàng)目可以正常調(diào)用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中移除兩個(gè)方法
#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文件中增加如下代碼跃巡,并繪制一個(gè)button
#import "SVProgressHUD.h"
-(IBAction)clickAction:(id)sender{
[SVProgressHUD showSuccessWithStatus:@"Hello,Demo"];
}
6、運(yùn)行程序,點(diǎn)擊按鈕牧愁,能正確看到彈窗即為成功素邪。
五、MyLib的基礎(chǔ)配置
1猪半、MyLib工程Build Setting配置
把Mach-O Type 設(shè)置為Static Library
確認(rèn)Other Linker Flags 中存在 -ObjC
2兔朦、創(chuàng)建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、設(shè)置暴露給外界的頭文件
MyLib --> Build Phases --> Headers--> Public
4磨确、修改MyLib.h文件
增加一行引用
#import "HelloObject.h"
六沽甥、MyLibDemo去調(diào)用MyLib庫
1、配置Framework的引用
MyLibDemo --> Build Phases --> Link Binary With Libraries --> 添加MyLib
2乏奥、調(diào)用Framework中的對(duì)象
修改ViewController.m文件內(nèi)容
#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安接、編譯項(xiàng)目,能正常跑起來就說明成功了
七、寫在最后
PS:目前我這么編譯盏檐,用真機(jī)測(cè)試歇式,最終上傳App Store是正常的不需要其他配置的。但其他開發(fā)者的資料中還會(huì)附帶其他的配置胡野。
僅收錄材失,自行嘗試。
http://www.reibang.com/p/f0b7eaa0ab11
這里面記錄了:
1硫豆、Architectures 編譯架構(gòu)設(shè)置
2龙巨、真機(jī)與模擬器的目標(biāo)文件合并
3、framework的腳本化打包
4熊响、framework中調(diào)用Bundle資源文件
http://www.reibang.com/p/5392f58dd821
這里面記錄了另一種framework靜態(tài)庫依賴Cocoapods第三方庫的方式旨别,只有一個(gè)project,但我編譯起來會(huì)有黃色警告汗茄,所以沒有采用