環(huán)境
CocoaPods 版本:1.15.2
芯片:Apple M1 Pro
這個(gè)場(chǎng)景月帝,我們是為了提供給所有人更加便捷的集成我們的封裝好的東西运敢。
創(chuàng)建的方式耻陕,官網(wǎng)也有介紹:https://guides.cocoapods.org/
Input:
通過命令 pod lib create 你的倉庫名稱
創(chuàng)建倉庫括眠,我這里以 lsj-FileManager
作為我的倉庫名稱
pod lib create lsj-FileManager
Output:使用的平臺(tái)
What platform do you want to use?? [ iOS / macOS ]
Input:
iOS
Output:選擇語言
What language do you want to use?? [ Swift / ObjC ]
Input:
ObjC
Output:是否創(chuàng)建演示應(yīng)用程序Demo
Would you like to include a demo application with your library? [ Yes / No ]
Input:
Yes
Output:您將使用哪些測(cè)試框架?
Which testing frameworks will you use? [ Specta / Kiwi / None ]
Input: 我個(gè)人認(rèn)為 Xcode 的 XCTest 挺好的概而,后續(xù)也可以自己加入對(duì)應(yīng)的 XCTest Target
None
Output:需要?jiǎng)?chuàng)建 UI 測(cè)試呼巷,后續(xù)也可以自行加入 Target
Would you like to do view based testing? [ Yes / No ]
Input: 是否要進(jìn)行基于視圖的測(cè)試?
Yes
Output:設(shè)置工程文件的前綴赎瑰,這個(gè)根據(jù)自己的代碼規(guī)范填寫
What is your class prefix?
Input:
L
Output:
Running pod install on your new library.
Analyzing dependencies
Downloading dependencies
Installing FBSnapshotTestCase (2.1.4)
Installing lsj-FileManager (0.1.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `lsj-FileManager.xcworkspace` for this project from now on.
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
[!] Your project does not explicitly specify the CocoaPods master specs repo. Since CDN is now used as the default, you may safely remove it from your repos directory via `pod repo remove master`. To suppress this warning please add `warn_for_unused_master_specs_repo => false` to your Podfile.
Ace! you're ready to go!
We will start you off by opening your project in Xcode
open 'lsj-FileManager/Example/lsj-FileManager.xcworkspace'
To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `https://guides.cocoapods.org/making/making-a-cocoapod`.
到這里王悍,倉庫已經(jīng)創(chuàng)建好了,終端會(huì)打開你的項(xiàng)目
在倉庫中餐曼,添加我們的代碼
在工程的Pods/Development/Pods/lsj-FileManager/
目錄下压储,有一個(gè) ReplaceMe
文件,
是存放我們文件的位置源譬,不能直接在 lsj-FileManager
右鍵 new->File
集惋,
因?yàn)檫@是一個(gè)虛擬路徑,需要我們手動(dòng)導(dǎo)航進(jìn)入 Classes
目錄中瓶佳,
可以通過右鍵 ReplaceMe
文件 Show In Finder
芋膘,進(jìn)入到 Classes
,獲取路徑
在 Example 中去使用它霸饲,Example 項(xiàng)目安裝你的pod,提供給用戶使用 Demo
Input:進(jìn)入 Example 目錄臂拓,Pod install
cd Example
pod install
Output:
Analyzing dependencies
Downloading dependencies
Installing lsj-FileManager 0.1.0
Generating Pods project
Integrating client project
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
創(chuàng)建 Git 倉庫(備用厚脉,后續(xù)填入 .podspec 文件中的 source
字段中)
校驗(yàn)我們的 .podspec 文件
Input:
pod lib lint lsj-FileManager.podspec
Output:summary: The summary is not meaningful 需要我們完善 summary
-> lsj-FileManager (0.1.0)
- WARN | summary: The summary is not meaningful.
- NOTE | url: The URL (https://github.com/lishangjing/lsj-FileManager) is not reachable.
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | [iOS] xcodebuild: note: Building targets in dependency order
- NOTE | [iOS] xcodebuild: note: Target dependency graph (3 targets)
- NOTE | [iOS] xcodebuild: note: Signing static framework with --generate-pre-encrypt-hashes (in target 'Pods-App' from project 'Pods')
- NOTE | [iOS] xcodebuild: /var/folders/cs/08c4rp4s4_l39wwhn08jt3sc0000gn/T/CocoaPods-Lint-20240317-8175-8r0xaa-lsj-FileManager/App.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'App' from project 'App')
- NOTE | [iOS] xcodebuild: Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'Pods-App' from project 'Pods')
- NOTE | [iOS] xcodebuild: Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'lsj-FileManager' from project 'Pods')
[!] lsj-FileManager did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
You can use the `--no-clean` option to inspect any issue.
完善 .podspec 文件中的 s.summary 、 s.description
Input:
pod lib lint lsj-FileManager.podspec
Output:lsj-FileManager passed validation. 校驗(yàn)通過
-> lsj-FileManager (0.1.0)
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | [iOS] xcodebuild: note: Building targets in dependency order
- NOTE | [iOS] xcodebuild: note: Target dependency graph (3 targets)
- NOTE | [iOS] xcodebuild: note: Signing static framework with --generate-pre-encrypt-hashes (in target 'Pods-App' from project 'Pods')
- NOTE | [iOS] xcodebuild: Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'Pods-App' from project 'Pods')
- NOTE | [iOS] xcodebuild: /var/folders/cs/08c4rp4s4_l39wwhn08jt3sc0000gn/T/CocoaPods-Lint-20240317-8554-8ralh0-lsj-FileManager/App.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'App' from project 'App')
- NOTE | [iOS] xcodebuild: Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'lsj-FileManager' from project 'Pods')
lsj-FileManager passed validation.
推送倉庫代碼到 Git
# 進(jìn)如項(xiàng)目根目錄
git init
git add .
git commit -m 'Initial Commit'
git remote add origin https://github.com/lishangjing-spec/lsj-FileManager.git
git branch -M master
git push -u origin master
在 .podspec 文件中我們可以看到
s.source = { :git => 'https://github.com/lishangjing-spec/lsj-FileManager.git', :tag => s.version.to_s }
這里指的是胶惰,我們依賴的下載地址是:
https://github.com/lishangjing-spec/lsj-FileManager.git
同時(shí)傻工,指向的是:s.version
tag
在 .podspec
中 s.version = 0.1.0
這是默認(rèn)的設(shè)置,我們可以自行更改,也可以遵循這個(gè)規(guī)則
遵循規(guī)則中捆,給我們最新的commit打上tag鸯匹,讓倉庫能引用到我們的代碼
Input:
git tag 0.1.0
git push origin 0.1.0
Output:
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:lishangjing-spec/lsj-FileManager.git
* [new tag] 0.1.0 -> 0.1.0
推送項(xiàng)目到 Cocoapods
Input:
pod trunk push lsj-FileManager.podspec
Output:
Updating spec repo `trunk`
Validating podspec
-> lsj-FileManager
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | [iOS] xcodebuild: note: Building targets in dependency order
- NOTE | [iOS] xcodebuild: note: Target dependency graph (3 targets)
- NOTE | [iOS] xcodebuild: note: Signing static framework with --generate-pre-encrypt-hashes (in target 'Pods-App' from project 'Pods')
- NOTE | [iOS] xcodebuild: Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'Pods-App' from project 'Pods')
- NOTE | [iOS] xcodebuild: /var/folders/cs/08c4rp4s4_l39wwhn08jt3sc0000gn/T/CocoaPods-Lint-20240317-16091-pb1xlo-lsj-FileManager/App.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'App' from project 'App')
- NOTE | [iOS] xcodebuild: Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'lsj-FileManager' from project 'Pods')
Updating spec repo `trunk`
--------------------------------------------------------------------------------
?? Congrats
?? lsj-FileManager (0.1.0) successfully published
?? March 17th, 08:27
?? https://cocoapods.org/pods/lsj-FileManager
?? Tell your friends!
上傳完成
[F&A]
[!] Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.
首次上傳或過久沒上傳,需要重新注冊(cè)
Input:
# 接受 Cocoapods 的郵箱泄伪,以及你的名稱(例如:帥哥)
pod trunk register 'xxx@qq.com' 'Name'
Output:進(jìn)入郵箱殴蓬,找到并打開驗(yàn)證鏈接
[!] Please verify the session by clicking the link in the verification email that has been sent to xxx@qq.com
Input:
pod trunk push XXXXX.podspec
.podspec 文件的屬性介紹
s.name:名稱
s.version:版本號(hào)
s.summary:總結(jié)
s.description:描述
s.homepage:倉庫主頁(作用于用戶訪問倉庫首頁)
s.license:開源協(xié)議
s.author:作者
s.source:用戶pod時(shí),依賴?yán)〉牡刂?br>
s.ios.deployment_target:依賴支持的版本號(hào)
s.source_files:項(xiàng)目文件路徑
s.resource_bundles:項(xiàng)目資源文件路徑
s.dependency:項(xiàng)目綁定的其他三方依賴
s.frameworks:項(xiàng)目綁定的系統(tǒng) Framework