1. 創(chuàng)建Spec Repos
? ? Spec repo 包含了所有私有庫的索引, 是所有 podspec 文件的倉庫, pod安裝后, 會在 mac 本地 ~/.cocoapods/repos/? 目錄下生成自定義私有庫對應(yīng)的Repos.
? ? 1.1 創(chuàng)建遠(yuǎn)程私有庫
? ? 可以在 github 或者 osChina 等平臺創(chuàng)建私有庫 (osChina 免費(fèi)).
? ? 1.2 關(guān)聯(lián)私有庫
pod repo add [私有庫] [遠(yuǎn)程庫 url]
之后在~/.cocoapods/repos/ 目錄下就同步了遠(yuǎn)程庫repo.
2. 創(chuàng)建 lib
? ? 為第一步創(chuàng)建的空倉庫, 添加庫文件!
? ? 2.1 在遠(yuǎn)端創(chuàng)建私有項(xiàng)目, JJ_Lib;
? ? 參照1.1創(chuàng)建庫文件JJ_Lib.
? ? 2.1 本地創(chuàng)建項(xiàng)目, 將庫文件引入工程, 關(guān)聯(lián)遠(yuǎn)端的庫.
pod lib create JJ_Lib
? ? 2.2 將寫好的庫文件替換測試項(xiàng)目中的 replaceme.m 文件.
? ?在 Podfile 文件中, 引用本地的庫文件
pod 'JJ_Lib', :path => '../' # 指向庫文件所在路徑
然后執(zhí)行
pod install # 安裝依賴庫
打開項(xiàng)目工程遂蛀,可以看到庫文件都被加載到Pods子項(xiàng)目中了, 不過它們并沒有在Pods目錄下,而是跟測試項(xiàng)目一樣存在于Development Pods/JJ_Lib中浩姥,這是因?yàn)槲覀兪窃诒镜販y試犹撒,而沒有把podspec文件添加到Spec Repo中的緣故市栗。編譯項(xiàng)目, 測試是否成功引入的庫文件.
????2.3 將本地 lib 關(guān)聯(lián)到遠(yuǎn)端庫
git add .
git commit -m "first commit"
git remote add origin?https://gitee.com/...i/JJ_Lib.git
git push -u origin master
3. 配置 podspec 文件
????3.1 打開項(xiàng)目中 .podspec文件設(shè)置對應(yīng)參數(shù), 參照官方說明Specs and the Specs Repo手動創(chuàng)建
? ??????A Podspec, or Spec, describes a version of a Pod library. One Pod, over the course of time, will have many Specs. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description.
Pod::Spec.new do |spec|
spec.name = 'libPusher'
spec.version = '1.3'
spec.license = 'MIT'
spec.summary = 'An Objective-C client for the Pusher.com service'
spec.homepage = 'https://github.com/lukeredpath/libPusher'
spec.author = 'Luke Redpath'
spec.source = { :git => 'git://github.com/lukeredpath/libPusher.git', :tag => 'v1.3' }
spec.source_files = 'Library/*'
spec.requires_arc = true spec.dependency 'SocketRocket'
end
????3.2 檢測是否可用
pod lib lint
????3.3 引用本地庫
pod 'JJ_Lib', :podspec => '../JJ_Lib.podspec' # 指定podspec文件
? ? 3.4?向Spec Repo提交podspec?
$ pod repo push MySpecs JJ_Lib.podspec
4. 在pod 中驗(yàn)證是否成功
#私有Spec Repo
source 'https://gitee.com/....git'
pod 'JJ_Lib', '~> 0.1.0'