让你的项目支持Cocoa Pods,作为第三方库方便的被别人使用:
本案前提
你已经有一个项目,并且上传到了gitbug上
项目含有liecnce文件(没有的话,后面校验不会通过)
准备工作一:注册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
然后会收到邮件,点击邮件链接确认
准备工作二:为你的项目添加PodSpec
在当前工作目录中创建一个名为NAME.podspec的PodSpec
pod spec create [NAME|https://github.com/USER/REPO]
编辑本地生成的NAME.podspec文件
一个简单的例子:
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
校验:
pod spec lint [NAME.podspec|DIRECTORY|http://PATH/NAME.podspec ...]
或 pod lib lint
或 pod spec lint --allow-warnings --verbose NAME.podspec 显示错误信息和警告
如果有错误就根据提示修改NAME.podspec
确认无误,提交code到git仓库中,并打上tag版本号
创建Spec Repo
pod repo add NAME URL [BRANCH]
如:
pod repo add NAME http://PATH/NAME.podspec
远程代码被拷贝在本地,在 ~/.cocoapods/repos/. 中可以查看
这样我们在一天github上的项目就被指定为Cocoa pods中名为NAME的项目
向Spec Repo提交podspec
#前面是本地Repo名字 后面是podspec名字
pod repo push REPO_NAME SPEC_NAME.podspec
如:
pod repo push myPods somePods.podspec
在项目中使用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