cocoapods官網查看
- 創建Podspec描述文件,cd 到文件的跟目錄下,在終端中輸入
pod spec create 描述文件名稱
,一般描述文件名稱最好和項目名稱一致。
pod spec create TestLib
Snip20171003_1.png
- 在項目目錄中可以查看到已創建成功的
spec描述文件
Snip20171003_2.png
- 用Xcode工具 打開項目中的
spec描述文件
在文件中 需要設置以下內容:
s.name = "TestLib" // 名稱
s.version = "0.0.1" // 版本
s.summary = "A short description of TestLib." // 簡介
s.description = “TestLib, 這個是詳細描述 一定要注意! 字數比s.summary長 ”
s.homepage = "https://github.com/Mrhuangchina/testFiel" // 首頁 以TestLib結尾。即以spec描述文件名稱結尾 可以換成倉庫地址
s.license = "MIT"
s.author = { "Mrhuangchina" => "xxxx@qq.com" } //這里的是你的Github里的名字 還要你的登錄帳號郵箱
Or just: s.author = "Mrhuangchina"
s.authors = { "Mrhuangchina" => "xxxx@qq.com" } //這里的是你的Github里的名字 還要你的登錄帳號郵箱
// source 這里 將改成你的spec描述文件的倉庫地址 tag 和s.version 版本 保持一致 也就是Github倉庫中的releases版本號
s.source = { :git => "https://github.com/Mrhuangchina/testFiel.git", :tag => "#{s.version}" }
// 在指定該的文件中 ** 通配符 標示目錄 *.{h,m}:* 代表的是文件夾
s.source_files = "Classes", "Classes/**/*.{h,m}"
s.exclude_files = "Classes/Exclude"
Pod::Spec.new do |s|
s.name = "PodTestLibrary" #名稱
s.version = "0.1.0" #版本號
s.summary = "Just Testing." #簡短介紹,下面是詳細介紹
s.description = <<-DESC
Testing Private Podspec.
* Markdown format.
* Don't worry about the indent, we strip it!
DESC
s.homepage = "https://coding.net/u/wtlucky/p/podTestLibrary" #主頁,這里要填寫可以訪問到的地址,不然驗證不通過
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2" #截圖
s.license = 'MIT' #開源協議
s.author = { "wtlucky" => "wtlucky@foxmail.com" } #作者信息
s.source = { :git => "https://coding.net/wtlucky/podTestLibrary.git", :tag => "0.1.0" } #項目地址,這里不支持ssh的地址,驗證不通過,只支持HTTP和HTTPS,最好使用HTTPS
# s.social_media_url = 'https://twitter.com/<twitter_username>' #多媒體介紹地址
s.platform = :ios, '7.0' #支持的平臺及版本
s.requires_arc = true #是否使用ARC,如果指定具體文件,則具體的問題使用ARC
s.source_files = 'Pod/Classes/**/*' #代碼源文件地址,**/*表示Classes目錄及其子目錄下所有文件,如果有多個目錄下則用逗號分開,如果需要在項目中分組顯示,這里也要做相應的設置
s.resource_bundles = {
'PodTestLibrary' => ['Pod/Assets/*.png']
} #資源文件地址
s.public_header_files = 'Pod/Classes/**/*.h' #公開頭文件地址
s.frameworks = 'UIKit' #所需的framework,多個用逗號隔開
s.dependency 'AFNetworking', '~> 2.3' #依賴關系,該項目所依賴的其他庫,如果有多個需要填寫多個s.dependency
end</twitter_username>
Snip20171003_4.png
- 在上述設置
spec描述文件
中,我們看到tag => "#{s.version}
tag
和spec描述文件
版本號需要一致,但我們并沒有設置tag
,所以接下來需要設置tag
git tag '0.0.1' //設置tag 并且tag值必須和spec描述文件version一致
git push --tags // 將tag 值 push 到遠程倉庫。
Snip20171003_5.png
Snip20171003_6.png
-
cocoapods
官網中找到GUIDES
里并找到Getting setup with Trunk
注冊Trunk,其Trunk作用則是將我們之前創建的spec描述文件
上傳到cocoapods
遠程索引庫中。
$ pod trunk register orta@cocoapods.org 'Orta Therox' --description='macbook air' // 即下面這行解釋 description 描述信息(可寫可不寫)
$ pod trunk register 郵箱地址 '名字' --verbose //--verbose 打印一些詳細信息
Snip20171003_8.png
在你剛剛填寫的郵箱中打開收到的郵件注意有可能會在你的垃圾箱里,找到郵件打開里面的鏈接則完成顯示如下圖表示成功:
Snip20171003_11.png
依據剛剛驗證的網站中的提示:在終端中輸入:
pod trunk push 描述文件名稱
Snip20171003_12.png
-> TestLib (0.0.1)
- ERROR | file patterns: The `source_files` pattern did not match any file.
[!] The spec did not pass validation, due to 1 error.
這個是在指定共享的類庫時, 文件路徑不對, 也就是設置 s.source_files
字段時, 發生了錯誤, 這里的路徑是相對于TestLib.podspec
文件的, 如果是與TestLib.podspec
同級的文件夾, 直接寫文件夾名稱即可, 如:
s.source_files = "TestLib"
如果有多級目錄, 一定要逐級添加. 這里也可以這么寫:
s.source_files = "TestLib/*.{h,m}"
需要注意的是s.source_files參數,如果配置為s.source_files = '/*.{h,m}’,會報錯:
- ERROR | File Patterns: File patterns must be relative and cannot start with a slash (source_files).
其它可能的報錯:
- ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.
- pod search
項目名稱
來驗證是否上傳到檢索庫成功- 搜索不到
Unable to find a pod with name, author, summary, or description matching TestLib.
- 搜索不到
- 解決辦法:
- 1.pod install --repo-update
- 2.或者全部刪除:使用命令:rm ~/Library/Caches/CocoaPods/search_index.json
- 3.重新search GKFramework
可參考 cocoapods Error
- —————————————————————————————
-
cocoapods 本地私有庫的使用
- 在本地私有庫的文件中先創建一個
spec
文件
Snip20171007_1.png - 修改
spec
文件中的source_file
的路徑,因為是本地私有庫文件 所以直接刪除遠程庫配置的git
路徑中的URL
。
Snip20171007_2.png - 進入到需要引用本地私有庫的工程文件中,并且創建
Podfile
文件
Snip20171007_3.png - 修改
Podfile
文件,:patch =>'../TestLib/TestLib'
代表在某個文件路徑下尋找到spec
文件,否則會自動在遠程索引庫中去尋找。
Snip20171007_5.png -
Pod install
安裝本地私有庫文件,并可以在工程文件中使用。
- 在本地私有庫的文件中先創建一個
- —————————————————————————————
-
cocoapods 遠程私有庫的使用