CocoaPods 系列之一 制作公開庫
CocoaPods 系列之二 更新公開庫
CocoaPods 系列之三 Podspec 語法說明
CocoaPods 系列之四 Podspec subspec
CocoaPods 系列之五 Private Pods(譯文) 制作私有庫
CocoaPods 系列之六 Private Pods 制作私有庫從0到1
CocoaPods 系列之七 我遇到的驗證不過
做私有庫前的知識準備:
1 先學會制作公開庫,否則白扯
2 會使用git
使用私有庫兩種方式,第一種有Spec的庫,第二種不適用私有的spec庫,我們先來看第一種
Private Pods
私有庫
CocoaPods is a great tool not only for adding open source code to your project, but also for sharing components across projects. You can use a private Spec Repo to do this.
CocoaPods是一個很好用的工具,不僅能添加公開代碼。而且能夠制作私有庫。
There are a few steps to getting a private pods setup for your project; creating a private repository for them, letting CocoaPods know where to find it and adding the podspecs to the repository.
制作私有庫的步驟是:創建私有倉庫,把podspec添加到倉庫。
1 Create a Private Spec Repo
1 創建私有的Spec Repo
To work with your collection of private pods, we suggest creating your own Spec repo. This should be in a location that is accessible to all who will use the repo.
為了制作私有庫,我們建議創建你自己的Spec repo。私有庫的權限開放給需要使用庫的人。
注解: 例如cocoapods的官方倉庫https://github.com/CocoaPods/Specs,把所有的公開庫的PodSpec文件放到倉庫里,相當于這是一個索引庫。
You do not need to fork the CocoaPods/Specs Master repo. Make sure that everyone on your team has access to this repo, but it does not need to be public.
2 Add your Private Repo to your CocoaPods installation
2 添加私有庫到你的電腦本地
命令:
$ pod repo add REPO_NAME SOURCE_URL
執行完整個命令后
$ cd ~/.cocoapods/repos/REPO_NAME
$ pod repo lint .
注解:我在碼云制作了一個空的倉庫,然后執行
pod repo add Haisheng git@gitee.com:haisenv/test_private_library.git
然后:
cd /Users/XXXX/.cocoapods/repos/Haisheng
執行:
pod repo lint .
輸出:
All the specs passed validation.
3 Add your Podspec to your repo
3 添加Podspec文件到你的repo庫里
Make sure you've tagged and versioned your source appropriately, then run:
確定你已經正確的制作了Podspec文件,然后執行
$ pod repo push REPO_NAME SPEC_NAME.podspec
注解:這里我使用的是測試的公開課,執行了
pod repo push Haisheng HSTestLib.podspec
執行這個步驟后 在我的本地和碼云私有庫的地址都多了一個東西(原來不只是改變本地,這個命令還把本地的repo推送到了倉庫)如下圖
That's it!
Your private Pod is ready to be used in a Podfile. You can use the spec repository with the source
directive in your Podfile as shown in the following example:
好了,你的私有庫已經準備好在Podfile中使用了。
How to remove a Private Repo
如何移除私有庫
pod repo remove [name]
再來看第二種
第一步 把工程寫好,代碼推送到私有庫上
第二步 pod spec create GoGoGo 創建podSpec文件,配置文件,配置后驗證通過
- 使用這種方式的時候一定注意庫文件和podspec文件一定要放在根目錄,默認去根目錄尋找到podSpec文件然后去加載文件去
第三步 在Podfile寫入
pod 'GoGoGo' , :git => 'git@gitee.com:haisenv/GoGoGoSdk.git',:branch => 'master'
這里不需要添加source。
使用這種方式,更改代碼后,更新就好,不需要tag,實用。
第四步
pod install
原理猜測
前提使用git管理代碼
一個使用庫的指定使用哪個版本,一個庫里那么多版本,所以要指定,或者分支或者tag;一個是提供庫的。如何把這倆者連接起來,那么podSpec文件就是橋梁,它規定了庫的git地址,分享的庫文件,依賴文件等等。