CocoaPods公有/私有库管理
创建公有库
注册 CocoaPods 账号
注册一个CocoaPods账号,我们使用终端注册, email 用你的 GitHub 邮箱
pod trunk register 'GitHub_email' 'user_name' --verbose
查看注册信息
pod trunk me
创建 git 仓库
在 GitHub 创建一个公开项目,项目中必须包含几个文件 * LICENSE: 开源许可证 * README.md: 仓库说明 * CRMediator.podspec: CocoaPods 的描述文件
创建 .podspec
pod spec create CRMediator
- 修改描述文件,例如: ``` Pod::Spec.new do |s| s.name = ‘CRMediator’ s.summary = ‘组件化中间件’ s.version = ‘0.0.1’ s.homepage = ‘https://github.com/cocoaroger/CRMediator' s.license = { :type => ‘MIT’, :file => ‘LICENSE’ } s.author = { ‘cocoaroger’ => ‘coacoaroger@gmail.com’ } s.requires_arc = true s.platform = :ios, ‘8.0’ s.source = { :git => ‘https://github.com/cocoaroger/CRMediator.git', :tag => s.version.to_s }
s.source_files = ‘CRMediator/*.{h,m}’ end
* 将修改后的文件提交到 GitHub,在 GitHub 添加一个叫 0.0.1 的 release 版本
### 添加对swift的支持
echo “3.0” > .swift-version
### 执行验证命令
pod spec lint CRMediator.podspec
如果出现如下提示说明成功了
CRMediator.podspec passed validation.
### 提交到 CocoaPods
pod trunk push CRMediator.podspec
正常情况的话,就算完成了,更新版本也是这个命令
# 创建私有仓库
### 在 GitHub 新建一个空白项目
例如:git@github.com:cr-atomic/CRPrivateRepos.git
### 创建私有 podspecs
在 Terminal 中输入,用于创建私有仓库
pod repo add [私有podspecs名字] [私有podspecs的远程地址]
例如:
pod repo add CRPrivateRepos git@github.com:cr-atomic/CRPrivateRepos.git
此时如果成功的话,进入到~/.cocoapods/repos目录下就可以看到 CRPrivateRepos 这个目录
### 创建代码仓库
创建 .swift-version
echo “3.0” > .swift-version
添加 LICENSE
MIT License
Copyright © 2018 cr-atomic
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
创建 .podspec
pod spec create MyAdditions
验证podspec是否正确
pod lib lint
私有库引用另一个私有库的验证,s.dependency 的第三方库必须指定版本号
s.dependency ‘B_Category’, ‘~> 0.0.1’
验证命令
pod lib lint –sources=‘git@github.com:cr-atomic/CRPrivateRepos.git,https://github.com/CocoaPods/Specs.git'
将所有文件提交到 GitHub
### 将 podspec 推送到版本库
pod repo push CRPrivateRepos MyAdditions.podspec
更新版本库命令
pod repo update CRPrivateRepos
### 使用私有库
在 Podfile 文件顶部添加:
source ‘https://github.com/cr-atomic/CRPrivateRepos.git' ```