作為一名資深的 iOS開發(fā),在開發(fā)過程中會用到大量的 category,以及一些常用的宏定義和github 一些常用的開源庫,如果全都是網(wǎng)往目中拖得話會顯得比較無力、麻煩,這本身就是組件化程度比較高的東西,完全沒有必要一個一個的往項目中拖,現(xiàn)在有一個非常好用的方法來分享給大家。(當然了網(wǎng)上的博客很多,但是我要打造一個非常簡潔便利的方法來讓大家去管理自己的私有庫)。
1.首先你得有一個 github,或者 coding亦或是 oschina 等代碼托管平臺的賬號(個人推薦 Coding 和 oschina,原因是 Coding,和oschina 是可以免費創(chuàng)建私有項目的,而github是需要收費的)
-
2.然后呢你需要在 你得代碼托管平臺上創(chuàng)建兩個項目(一個是你得私有源,另一個是你想要引用的私有庫)
那就拿我的我的做個例子吧~
這是我的私有源
私有源倉庫1
這是我要引用的私有庫
這是我要引用的私有庫 3.創(chuàng)建完倉庫之后,緊接著在本地創(chuàng)建兩個文件夾,和創(chuàng)建倉庫時的名字一樣YCPodSpec(下文稱地址1),和YCBaseCategory(下文稱地址2)。
-
4.然后呢在在地址2中創(chuàng)建一個你的項目比如說我的(下面的 category 就是你在 cocoapods 中即將要引用的東西)
創(chuàng)建的項目
然后在終端輸入命令
cd 地址2中你創(chuàng)建項目的路徑(一般直接拖就 OK)
pod spec create YCBaseCategory
然后在你的地址2中會出現(xiàn)一個叫YCBaseCategory.podspec的文件,用 Xcode 打開它編輯
像我這樣對應改一下
Pod::Spec.new do |s|
s.name = "YCBaseCategory"
s.authors = "???"
s.homepage = "git@git.coding.net:???/YCBaseCategory.git"
s.summary = "YCBaseCategory"
s.version = "1.0.0"
s.platform = :ios, "8.0"
s.source = { :git => "git@git.coding.net:???/YCBaseCategory.git", :tag => s.version }
s.source_files = "YCBaseCategory/Category/*.{h,m}"
#s.dependency 'MJRefresh'
end
然后呢在打開命令行輸入以下命令
git init
git add .
git commit -m 'category'
git remote add origin https://git.coding.net/???/YCBaseCategory.git
git push -u origin master
添加 tag用來區(qū)分版本
git tag 1.0.0
git push --tags
現(xiàn)在呢距離完成已經(jīng)到了50%了
- 5.還記得另一個倉庫的名字么 YCPodSpec這時候私有源該上場了,首先你把地址1添加到你的 cocopods 的源中去
pod repo add YCPodSpec https://git.coding.net/???/YCPodSpec.git
這里呢如果遇到這個問題的就是托管平臺沒有配公鑰和私鑰
-> YCBaseCategory (1.0.0)
- WARN | attributes: Missing required attribute `license`.
- WARN | license: Missing license type.
- WARN | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred.
- WARN | url: There was a problem validating the URL git@git.coding.net:CoderAn/YCBaseCategory.git.
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone git@git.coding.net:CoderAn/YCBaseCategory.git /var/folders/4y/z_qs1rx56892cbwxb53kkhyw0000gn/T/d20170717-9015-13p049l --template= --single-branch --depth 1 --branch 1.0.0
Cloning into '/var/folders/4y/z_qs1rx56892cbwxb53kkhyw0000gn/T/d20170717-9015-13p049l'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
) during validation.
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
** 解決:添加公鑰和私鑰 **
** 終端輸入 ssh-keygen**
然后在這個路徑中
cd ~/.ssh
把生成好的公鑰復制到托管平臺這里去(以 coding 為例)

檢查加沒加到 cocoapods源中去
輸入命令
cd ~/.cocoapods/repos
ls

如果沒有出現(xiàn)問題呢就在地址1中創(chuàng)建一個文件夾名稱YCBaseCategory(就是你需要被管理的私有庫),然后在里面在創(chuàng)建相關的版本號(就是剛才你項目中的 tag 值1.0.0)類似于這樣

然后呢在對應版本號中把這個文件復制進來
YCBaseCategory.podspec緊接著呢開始驗證
pod spec lint YCBaseCategory.podspec --allow-warnings
然后推到 代碼托管平臺
git init
git add .
git commit -m "first commit"
git remote add origin https://git.coding.net/CoderAn/YCPodSpec.git
git push -u origin master
更新你的私有源
然后進入你任意的一個項目在 Podfile 中添加

對了還有最重要的一點---你的私有源沒有更新到最新版現(xiàn)在你的私有源還是空的
那咱們就更新吧
終端
cd 你的任意一個項目
pod repo update (這是升級 cocoapods 中所有的源,包括 cocoapods 默認的那個私有源)
你要是升級某一個呢就用這個命令吧
pod repo update YCPodSpec(替換成你的源)
如果沒有報紅的話就是成功了,一般沒什么問題如果有的話下面評論,或者自行百度
然后緊接著在你剛才修改Podfile的那個項目
pod install
哈哈大功告成1.0版本的私有源成功面世
來看看我的吧

哈哈哈現(xiàn)在你還在等什么趕快行動起來吧~~~
可能有些同學會遇到一些問題:
問題1.
warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777。
提示含義:
目錄被賦予777的權限,不安全。
如何解決:
將提示權限改為775,問題即可解決。
具體實現(xiàn):
在終端寫入下列命令行,即可消除上面的提示。
sudo chmod go-w /usr/local/bin
sudo chmod 775 /usr/local
問題2.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- colored2 (LoadError)
提示缺少 colored2, 可使用
sudo gem install colored2
進行安裝, 提示缺什么就裝什么。


