讓你的項(xiàng)目支持Cocoa Pods,作為第三方庫(kù)方便的被別人使用:
本案前提
你已經(jīng)有一個(gè)項(xiàng)目,并且上傳到了gitbug上
項(xiàng)目含有l(wèi)iecnce文件(沒(méi)有的話,后面校驗(yàn)不會(huì)通過(guò))
準(zhǔn)備工作一:注冊(cè)trunk
pod trunk register EMAIL [NAME]
Examples:
$ pod trunk register eloy@example.com `Eloy Durán` --description=`Personal Laptop`
$ pod trunk register eloy@example.com --description=`Work Laptop`
$ pod trunk register eloy@example.com
然后會(huì)收到郵件,點(diǎn)擊郵件鏈接確認(rèn)
準(zhǔn)備工作二:為你的項(xiàng)目添加PodSpec
在當(dāng)前工作目錄中創(chuàng)建一個(gè)名為NAME.podspec的PodSpec
pod spec create [NAME|https://github.com/USER/REPO]
編輯本地生成的NAME.podspec文件
一個(gè)簡(jiǎn)單的例子:
Pod::Spec.new do |spec|
spec.name = 'Reachability'
spec.version = '3.1.0'
spec.license = { :type => 'BSD' }
spec.homepage = 'https://github.com/tonymillion/Reachability'
spec.authors = { 'Tony Million' => 'tonymillion@gmail.com' }
spec.summary = 'ARC and GCD Compatible Reachability Class for iOS and macOS.'
spec.source = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' }
spec.source_files = 'Reachability.h,m'
spec.framework = 'SystemConfiguration'
spec.requires_arc = true
end
校驗(yàn):
pod spec lint [NAME.podspec|DIRECTORY|http://PATH/NAME.podspec ...]
或 pod lib lint
或 pod spec lint --allow-warnings --verbose NAME.podspec 顯示錯(cuò)誤信息和警告
如果有錯(cuò)誤就根據(jù)提示修改NAME.podspec
確認(rèn)無(wú)誤,提交code到git倉(cāng)庫(kù)中,并打上tag版本號(hào)
創(chuàng)建Spec Repo
pod repo add NAME URL [BRANCH]
如:
pod repo add NAME http://PATH/NAME.podspec
遠(yuǎn)程代碼被拷貝在本地,在 ~/.cocoapods/repos/. 中可以查看
這樣我們?cè)谝惶靏ithub上的項(xiàng)目就被指定為Cocoa pods中名為NAME的項(xiàng)目
向Spec Repo提交podspec
#前面是本地Repo名字 后面是podspec名字
pod repo push REPO_NAME SPEC_NAME.podspec
如:
pod repo push myPods somePods.podspec
在項(xiàng)目中使用CocoaPods
touch Podfile
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Artsy/Specs.git'
platform :ios, '9.0'
inhibit_all_warnings!
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
# Has its own copy of OCMock
# and has access to GoogleAnalytics via the app
# that hosts the test target
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end