1. 创建自己的仓库
我是在https://gitee.com(前身是:git.oschina.net)上建的pod库。
比如我们创建的库名字为:FileSaveManager
如图
圈出部分是需要选中的选项
创建成功之后的结果是这样的:
2. 把仓库克隆到本地:
cd /Users/xxx/MyGitCode/iOSFileSave
git clone https://gitee.com/zzhrainbow/FileSaveManager.git
3. 向本地git仓库中添加创建Pods依赖库所需文件
后缀为.podspec文件
该文件为Pods依赖库的描述文件,每个Pods依赖库必须有且仅有那么一个描述文件。文件名称要和我们想创建的依赖库名称保持一致,我的FileSaveManager依赖库对应的文件名为FileSaveManager.podspec。
FileSaveManager.podspec 内容如下:
#
# Be sure to run `pod lib lint QLFileSaveManager.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'FileSaveManager'
s.version = '1.0.0'
s.summary = 'save file tool used on ios'
# 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!
s.description = <<-DESC
save file tool used on ios. luanguage is Object-C
DESC
s.homepage = 'https://gitee.com/zzhrainbow/FileSaveManager'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'rainbowboy' => 'zzhrainbow@163.com' }
s.source = { :git => 'https://gitee.com/zzhrainbow/FileSaveManager.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/'
s.ios.deployment_target = '7.0'
# s.platform =:ios, '7.0' 或者这样定义版本
# s.ios.deployment_target = '7.0'
# s.osx.deployment_target = '10.7'
s.source_files = 'FileSaveManager/*'
# s.resource_bundles = {
# 'FileSaveManager' => ['FileSaveManager/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
该文件是ruby文件,里面的条目都很容易知道含义。
其中需要说明的又几个参数:
①s.license
Pods依赖库使用的license类型,大家填上自己对应的选择即可。
②s.source_files
表示源文件的路径,注意这个路径是相对podspec文件而言的。
③s.frameworks
需要用到的frameworks,不需要加.frameworks后缀。
④LICENSE与README.md的位置
这两个文件要跟podspec放在同一级,不然执行命令git push origin master时会有警告:找不到这两个文件
这里贴一下正确的文件结构供大家参考
4. 验证
pod set the new version to 1.0.o
pod set the new tag to 1.0.0
执行pod lib lint
验证,成功的状态是:
FileSaveManager passed validation.
如果执行失败时会报告错误,通过命令:pod lib lint FileSaveManager . podspec --verbose
查看具体错误信息
5. 提交代码到仓库
git add .
git commit -m "Release 1.0.0." #提交注释
git tag '1.0.0'
git push --tags
git push origin master #这一步推送代码到仓库
6. 通过pod拉取代码
提交成功之后,就需要验证在工程里是否能通过pod拉取到代码
podfile 这样录入
pod 'FileSaveManager', :git => 'git@gitee.com:zzhrainbow/FileSaveManager.git', :tag =>'1.0.0'
终端(terminal)里这样执行:
pod install
成功时可以在工程里找到拉取到FileSaveManager工具,失败时会提示错误。