制作CocoaPod
手動創(chuàng)建
創(chuàng)建 spec 文件烂琴,手動創(chuàng)建項目并配置 podName.podspec
文件
pod spec create [podName]
自動創(chuàng)建
CocoaPods 官網(wǎng)推薦颜曾,會根據(jù)終端填入的選項按照 pod-template 模板生成工程充活,可以通過 --template-url
使用自定義的模板
pod lib create [podName]
通過 pod lib create
創(chuàng)建,會詢問下面 5 個選項:
- Objc 或 Swift
- 是否需要 Demo 工程
- 選擇測試框架
- 是否需要基于視圖的測試
- Objc 項目的前綴
最終,生成 Pod 模板,文件目錄結(jié)果如下:
image.png
-
Example
內(nèi)置了 Demo 工程唇辨,已經(jīng)引入了 Development Pod,每次修改 podspec 和 代碼能耻,需要在此目錄 pod install
-
podsName
需要配置 Pod 代碼的位置
-
podsName.podspec
Pod::Spec.new do |s| # pod 的名稱 s.name = 'podsName' # pod 的版本 s.version = '0.1.0' # pod 的簡介 s.summary = 'A short description of podsName.' # 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! # pod 的描述 s.description = <<-DESC TODO: Add long description of the pod here. DESC # pod 的主頁 s.homepage = 'https://github.com/harry/podsName' # 截圖 # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'xxx' => 'xxx@xxx.com' } # pod 的源赏枚,可以指定為 branch 或者 tag,默認使用與上面 version 一致的 tag s.source = { :git => 'https://github.com/xxx/podsName.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>' # 最低支持版本 s.ios.deployment_target = '9.0' # 引入的源文件 *代表全部匹配 s.source_files = 'podsName/Classes/**/*' # 引入的資源文件 # s.resource_bundles = { # 'podsName' => ['podsName/Assets/*.png'] # } # 頭文件 # s.public_header_files = 'Pod/Classes/**/*.h' # 依賴的系統(tǒng)庫 # s.frameworks = 'UIKit', 'MapKit' # 依賴的三方庫和版本 # s.dependency 'AFNetworking', '~> 2.3' #子模塊 subspec 'subSpecModule' do |sp| sp.source_files = 'Classes/subSpecModule' end end
檢查本地 Pod
在完成后可以通過 pod lib lint
本地檢查是否正確
cd ~/code/Pods/podsName
pod lib lint --allow-warnings
檢查遠程倉庫 Pod
將代碼推送到遠程倉庫后晓猛,并配置推送標簽版本嗡贺,最后使用 pod spec lint
。
git add -A && git commit -m "Release 0.0.1."
git tag '0.0.1'
git push --tags
pod spec lint --allow-warnings
部署 Pod
部署到 trunk
-
注冊
pod trunk register [emailAddress] 'userName' --description='macbook air'
-
部署
pod trunk push [NAME.podspec]
部署到私有源
在遠程倉庫創(chuàng)建一個私有的 Spec repo 倉庫
-
在電腦 CocoaPods 添加 repo
pod repo add REPO_NAME SOURCE_URL
-
部署到私有源
pod repo push REPO_NAME SPEC_NAME.podspec