CocoaPods是iOS開發用于管理第三方庫的 不可獲取的 工具,在使用別人庫的同時,我們有時候也想做一個自己的開源庫,所以看到這篇文章,你就應該準備入門了。
知識儲備:
一、Git使用
Git命令:
Git常用命令傳送門:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html熟悉下簡單的Git操作。
Git系統學習傳送門:
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/
二、cocoapods安裝和使用
CocoaPods官網:http://cocoapods.org/
CocoaPods安裝和使用:http://blog.csdn.net/sanjunsheng/article/details/28398455
Podfile文件編輯:http://blog.csdn.net/xdrt81y/article/details/30631595
制作自己的Pod開源庫
一、開源庫制作基本步驟:
1. 首先,申請一個 Github、或者Coding.net 賬號
2. GitHub或者coding上 創建一個倉庫
3. 把倉庫克隆到本地 (讓本地文件 和 倉庫建立連接)編輯倉庫內容
4. 倉庫內容整理好之后 創建 podspec文件 編輯文件 (這一步是關鍵)
5. 驗證 podspec文件格式是否正確
6. 提交倉庫到 cocoapod
7. 安裝pod倉庫
二、For Example
Ok,下面開始詳細講解:
1、申請賬號
GitHub :國際化的 比較大的開源平臺,個人非常喜歡。Github的目的是開源交流,如果普通賬號想要創建私有庫,是需要花錢的,怎奈何公司網絡太慢,我只是閑時才會去看看。
Coding.net: 中國的GitHub,支持國貨。這個平臺是可以免費享有 創建私有庫 權限的,推薦!!!!~~~~
2、在你所創建的平臺上 創建一個公有的 開源倉庫 (這里以Coding平臺的podTestLibrary 為例)
需要注意的是三個點:
1、倉庫名字 這個根據你項目 后者開源庫命名自定義就可以了。
2、項目是否開源 :開源庫 項目肯定是要開源的,毫無疑問。
3、License:通行證,最好是在平臺上創建,用Git 終端 工具創建倉庫默認都是不帶 MIT License文件的。這個文件表明,你允許別人訪問你的開運庫,就相當于是一個權限聲明。
3、把平臺上創建的倉庫 克隆到本地
$git clone podTestLibary
克隆到本地以后,就把網絡倉庫和本地倉庫創建聯系了。接下來,你就創建 包含你要分享的開源庫就好了。
$ pod repo add podTestLibraryhttps://git.coding.net/Kael_zzs/podTestLibrary.git
這個是Pod的方式 將倉庫克隆到本地 的pod repo庫中。
另:創建項目的時候,pod有個模板命令:
pod libcreate[your_project_name]
4、創建 podSpec文件。
```
# Be sure to run `pod lib lint QGGImagePicker.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name ? ? ? ? ? ? = "QGGImagePicker"
s.version ? ? ? ? ?= "0.0.1"
s.summary ? ? ? ? ?= "QGGImagePicker."
# This description is used to generate tags and improve search results.
# ? * Think: What does it do? Why did you write it? What is the focus?
# ? * Try to keep it short, snappy and to the point.
# ? * Write the description between the DESC delimiters below.
# ? * Finally, don't worry about the indent, CocoaPods strips it!
s.description ? ? ?= <<-DESC
A ImagePicker Like WeChat's ImagePicker
DESC
s.homepage ? ? ? ? = "https://github.com/infiniteQin/QGGImagePicker.git"
# s.screenshots ? ? = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
s.license ? ? ? ? ?= 'MIT'
s.author ? ? ? ? ? = { "changqin" => "changqin@ixiaopu.com" }
s.source ? ? ? ? ? = { :git => "https://github.com/infiniteQin/QGGImagePicker.git", :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/'
s.platform ? ? = :ios, '7.0'
s.requires_arc = true
s.source_files = 'Pod/Classes/**/*','Pod/Classes/**/**/*'
#s.resource_bundles = {
# ?'QGGImagePicker' => ['Pod/Assets/*.png']
#}
#s.resources = "Pod/*.xcassets"
# s.public_header_files = 'Pod/Classes/**/*.h'
s.frameworks = "UIKit", "AssetsLibrary"
s.dependency 'Masonry', '~> 0.6.3'
end
s.name="FYAlbum"開源庫名稱
s.version="1.0.1"開源庫版本(這個版本很關鍵,最好跟開源庫的穩定relese版本的tag 保持一致)
s.license="MIT"通行證
s.summary="Fast encryption string used on iOS, which implement by Objective-C."簡介
s.homepage="https://github.com/ifgyong/FYAlbum"開源庫主頁
s.author= {"fgyong"=>"fgyong@yeah.net"} ? ?作者信息
s.source= { :git =>"https://github.com/ifgyong/FYAlbum.git", :tag => s.version} ? 網絡倉庫地址
s.requires_arc=true是否是ARC
s.source_files="FYAlbum/*/*"資源文件路徑
s.platform= :ios,'8.0'支持平臺
s.framework='Foundation','UIKit'依賴的framework
s.dependency'Masonry','~> 0.6.3' 依賴的第三方庫
```
搞定這些參數,基本上就Ok了,然后就是git提交的問題了
git add -A && git commit -m "Release 0.1.0"
git tag '0.1.1' ? 注:s.version要和這里對應
git remote add origin git@github.com:sapphirezzz/ZInAppPurchase.git
git push --tags
git push origin master
5、驗證 podSpec文件 格式是否正確。
$pod lib lint ***.podSpec ?--allow-warnings --verbose
--allow-warnings:允許有警告 。即使有警告??, 也能驗證通過
--verbose:允許有編譯錯誤。即使有編譯錯誤也能通過驗證
驗證通過就可以上傳了
6、提交倉庫到Pod服務器。
最期待的一部操作:
$pod trunk push podTestLibary.podspec --allow-warnings
這一步耗時較多,耐心等待吧~
私有庫制作:
1、GitHub或者coding上 創建一個倉庫
這里需要創建的是一個私有倉庫
2、把倉庫克隆到本地 (讓本地文件 和 倉庫建立連接)編輯倉庫內容
3、倉庫內容整理好之后 創建 podspec文件 編輯文件 (這一步是關鍵)
4、驗證 podspec文件格式是否正確
5、提交倉庫到 cocoapod
6、制作索引文件 ?分發讀寫權限
pod ipc spec DataInterface.podspec >> DataInterface.podspec.json
7、安裝pod倉庫
私有庫使用:
首先,安裝cocoaPods;
然后,獲取作者的授權
接著,獲取作者的 索引文件(倉庫信息的json文件)
放到 ~/.cocoaPods 內repo 列表中
最后,按照正常的步驟導入項目就行了~