最近在给项目搞组件化,想到把拆分出来的组件单独维护,考虑cocoapods的易用,所以尝试着将一部分已经剥离出来的组件放在cocoapods上。
步骤(安装cocoapods步骤略过):
1.创建 *.podspec
在终端,进入项目的目录,执行命令:
//命令中 MXCCategory 是组件化模块的名称
$ pod spec create MXCCategory
2.编辑 *.podspec
Pod::Spec.new do |s|
s.name = "MXCCategory"
#版本号
s.version = "0.0.2"
#简介
s.summary = "test"
#描述
s.description = <<-DESC
Category经过整理后常识使用pods来管理
DESC
#项目主页
s.homepage = "https://github.com/evafan2003/"
#许可证
s.license = { :type => "MIT", :file => "LICENSE" }
#发布者信息
s.author = { "hefei" => "evafan2003@aliyun.com" }
#项目适用平台
s.platform = :ios, "8.0"
#项目主页
s.source = { :git => "https://github.com/evafan2003/CategoryRepertory.git", :branch => "master", :tag => "v#{s.version }" }
#项目主页
s.source_files = "Category", "Category/**/*.{h,m}"
#项目需要使用到的框架
# s.framework = "SomeFramework"
# s.frameworks = "SomeFramework", "AnotherFramework"
#项目使用到的系统依赖库
# s.library = "iconv"
# s.libraries = "iconv", "xml2"
#需要用到的cocoapods依赖库,不能依赖未发布的库
# s.dependency "JSONKit", "~> 1.4"
s.source一般可以这么写:
s.source = { :git => "https://github.com/evafan2003/CategoryRepertory.git", :commit => "68defea" }
s.source = { :git => "https://github.com/evafan2003/CategoryRepertory.git", :tag => 0.0.1 }
s.source = { :git => "https://github.com/evafan2003/CategoryRepertory.git", :tag => s.version }
3.创建并编辑LICENSE文件
The MIT License (MIT)
Copyright (c) 2018 evafan2003 <evafan2003@aliyun.com>
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.
如果发布到cocoapod这个是必须要有的,如果在创建Git仓库的时候没有创建这个文件,可以创建一个,内容格式按照上面的编辑就可以了。
4.将自己的项目打上tag标签
没啥说的,Git的相关操作
4.验证.podspec文件
到此检查一下你工程下面的文件, 你的项目, .podspec文件, LICENSE文件
然后执行命令
// --verbose 如果验证失败会报错误信息
pod spec lint MXCCategory.podspec --verbose
5.注册CocoaPods
6.发布
pod trunk push MXCCategory.podspec --allow-warnings
屏幕快照 2018-03-09 下午5.26.56.png
7.问题整理
pod install 出现 Unable to find a specification for xxxxx
在工程目录执行下面代码,更新pod仓库
pod repo update
网友评论