創(chuàng)建 Git 倉庫
創(chuàng)建 Git 倉庫,包含 MIT License
項目 clone 到本地,將 打包的 framework 拖入

工程文件夾
創(chuàng)建 pod
1、創(chuàng)建 podspec 文件
終端,cd 到倉庫目錄下,創(chuàng)建 podspec文件
pod spec create testSDK // testSDK 是 pod 庫名
testSDK.podspec文件如下

image.png
#
# Be sure to run `pod spec lint frameWorkName.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |spec|
# .spec 文件名
spec.name = "SDKName"
# SDK 版本號
spec.version = "1.0.0"
spec.summary = "SDK 的簡潔概述"
spec.description = "SDK 的介紹"
# 倉庫地址
spec.homepage = "https://gitee.com/bbavip/sdk-name”
#spec.license = "MIT"
spec.license = { :type => "MIT", :file => "LICENSE" }
# 用戶信息
spec.author = { “name” => “email@qq.com" }
spec.platform = :ios
spec.requires_arc = true
# 開源地址和版本號(同 tag 版本一致)
spec.source = { :git => "https://gitee.com/bbavip/sdk-name.git", :tag => "#{spec.version}" }
# 資源文件
spec.resource = 'Classes/frameWorkName.framework/PicResource.bundle'
# 開源出去的文件/文件夾
#spec.source_files = "Classes", "Classes/**/*.{h}"
spec.source_files = 'Classes/frameWorkName.framework/Headers/*.{h}'
# 公開的頭文件
#spec.public_header_files = "Classes/**/*.h"
spec.public_header_files = 'Classes/frameWorkName.framework/Headers/frameWorkHeader.h’
#spec.exclude_files = "Classes/Exclude"
#spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# 依賴的系統(tǒng)框架
spec.frameworks = 'AVKit','CoreGraphics','SystemConfiguration','AudioToolbox','QuartzCore','CoreLocation','AVFoundation','Foundation','UIKit'
# 依賴的系統(tǒng)靜態(tài)庫
spec.library = 'c++','z'
# 自己的 .framework
#spec.vendored_frameworks = "Classes/*.{framework}"
spec.vendored_frameworks = 'Classes/frameWorkName.framework'
# 自己的 .a
#spec.ios.vendored_libraries = "Classes/frameWorkName.a"
# 依賴的第三方 framework
spec.subspec 'iflyMSC' do |ifly|
ifly.source_files = 'Classes/iflyMSC.framework/Headers/*.{h}'
ifly.public_header_files = 'Classes/iflyMSC.framework/Headers/IFlyMSC.h'
ifly.vendored_frameworks = 'Classes/iflyMSC.framework'
end
# 依賴的第三方 pod 庫
spec.dependency "AFNetworking"
end
-
相關報錯
- ERROR | [iOS] file patterns: Thesource_filespattern did not match any file
source_files路徑問題,spec.source_files路徑是基于.podspec文件的。
2、驗證 podspec 文件
cd 到 testSDK.podspec文件所在文件夾
// 本地驗證
pod lib lint
// 允許警告,解決因警告導致驗證不過的問題;verbose:顯示驗證過程的詳細過程信息
pod lib lint --allow-warnings --verbose
相關報錯
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://xxx.git /var/folders/v_/v95fqz3x45n__zm562jddlhm0000gn/T/d20210819-53525-1tnf8eh --template= --single-branch --depth 1 --branch 1.0.5
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer (Xcode.app包的Developer的文件夾路徑)

驗證 spec - error2
原因:.podspec文件中 spec.platform = :iOS 導致的錯誤,應該是:spec.platform = :ios .
ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code
pod lib lint --allow-warnings --verbose --skip-import-validation
驗證成功:

podspec 驗證通過
3、Git 打 tag
git tag "1.0.0" // tag版本
git push --tags // 將 tag 推送到遠程倉庫
cocoapod 是依賴于tag版本的,必須打tag,
且tag版本與.podspec文件中的spec.version 版本要保持一致。
4、遠程驗證 podspec
// 本地和遠程 驗證
pod spec lint
5、發(fā)布到 cocoapod
cd 到.podspec文件所在
pod trunk push *.podspec --allow-warnings
trunk注冊
pod trunk register 你的郵箱@email.com --description= '名字'
按照提示,收到郵箱后驗證。
驗證后,再次執(zhí)行
pod trunk push *.podspec --allow-warnings
相關報錯
-
[!] Unable to accept duplicate entry for: XXXXX (1.0.0)
已存在版本號,不允許相同版本的提交,更換.podspec文件中的spec.version即可。 - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code
pod trunk push *.podspec --allow-warnings --skip-import-validation

cocoapod 庫成功
查看,終端執(zhí)行:
pod trunk me

image.png
6、搜索
pod search xxx // xxx: 剛剛push成功的庫
-
相關報錯
[!] Unable to find a pod with name, author, summary, or description matching xxx
清掉緩存后,再次搜索
rm ~/Library/Caches/CocoaPods/search_index.json
cocoapods 可能存在延遲,可稍待一段時間(時長不定)再進行搜索
7、刪除 pod 官方庫中某個意外版本
// SDKName:庫名 1.0.0:要刪除的版本
pod trunk delete SDKName 1.0.0

image.png
根據(jù)終端提示輸入 y,回車,即刪除此版本。