创建 spec 文件,手动创建项目并配置 podName.podspec
文件
pod spec create [podName]
CocoaPods 官网推荐,会根据终端填入的选项按照 pod-template 模板生成工程,可以通过 --template-url
使用自定义的模板
pod lib create [podName]
通过 pod lib create
创建,会询问下面 5 个选项:
最终,生成 Pod 模板,文件目录结果如下:
Example
内置了 Demo 工程,已经引入了 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'
# 依赖的系统库
# s.frameworks = 'UIKit', 'MapKit'
# 依赖的三方库和版本
# s.dependency 'AFNetworking', '~> 2.3'
#子模块
subspec 'subSpecModule' do |sp|
sp.source_files = 'Classes/subSpecModule'
end
end
在完成后可以通过 pod lib lint
本地检查是否正确
cd ~/code/Pods/podsName
pod lib lint --allow-warnings
将代码推送到远程仓库后,并配置推送标签版本,最后使用 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 register [emailAddress] 'userName' --description='macbook air'
部署
pod trunk push [NAME.podspec]
在远程仓库创建一个私有的 Spec repo 仓库
在电脑 CocoaPods 添加 repo
pod repo add REPO_NAME SOURCE_URL
部署到私有源
pod repo push REPO_NAME SPEC_NAME.podspec