版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wj610671226/article/details/76945173
iOS远程私有库的创建
这几天在研究远程私有库的使用,下面就记录一下自己研究的过程,带你一步步的创建自己的私有库。
工具和技能
- 第三方代码仓库,支持私有仓库(必须是免费的,土豪略过)
- CocoaPods的常用操作
- git的常用操作
操作步骤
1、创建CocoaPods库的模板
pod lib create DemoLib
2、将核心代码放入Classes目录,如果有资源文件放入Assets
3、测试代码
4、git 关联远程私有库
git remote add 私有库地址
5、上传代码到git仓库
git add .
git commit -m '更新信息'
git push 或者 git push origin master
git tag 0.1.0
git tag push --tags
6、创建一个私有库索引并添加到本地
pod repo add localSpec 私有库索引仓库
pod repo 查看是否添加成功
7、利用pod验证代码库
#本地验证
pod lib lint
#远程验证
pod spec lint
#远程私有库验证
pod spec lint --private
#推送到本地搜索库
pod repo push localSpec MyLib.podspec
创建私有库
1.首先在第三方仓库中创建一个私有仓库,我选用的是"码云",你当然也可以选择其他的。
2.利用CocoaPods创建一个库的模板文件
3.将编写的库代码拷贝到Classes文件中,我这里只是随意拷贝了一份代码
4.进入Example文件夹,在命令行利用pod install安装自己的库,测试是否正确,这一步略过
5.利用git将代码上传到私有仓库中,并打相应的tag
创建私有库的索引
1.同样在第三方仓库中创一个私有项目存储私有库的索引文件
2.在本地添加私有库索引文件,利用pod repo 查看
3.编辑之前创建的Mylib库的MyLib.podspec文件
注意:s.version的值一定要和之前的tag对应,否则后面的验证会不通过
4.验证MyLib.podspec文件,由于是私有库,注意查看报错信息
5.将MyLib.podspec文件添加到本地索引文件localSpec中,此时和自动同步到远程私有索引库中
6.查看是否添加成功
7.利用pod search 搜索自己的私有库
8.查看远程私有库的文件
创建一个项目安装自己的私有库来验证
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://git.oschina.net/TianTianKaiFa/MySpecs.git'
#source 'https://github.com/CocoaPods/Specs.git' 有其他第三方库,加上这句
target 'TestDemo' do
use_frameworks!
pod "MyLib"
end
- 自动化脚本
一键将修改的代码上传到git仓库,并更新到私有库索引库
#使用方法 ./upload.sh 更新信息 tag值 podspec文件名
message=${1}
tag=${2}
podspecName=${3}
method="使用方法:./upload.sh 更新信息 tag值 podspec文件名"
if [ ${#podspecName} -eq 0 ]
then
echo "参数不合法 - $method" & exit
fi
git add .
git commit -m "${message}"
git push origin master
git tag $tag 2> error.sh
error=$(cat ./error.sh)
if [ ${#error} -ne 0 ] #不等于零说明有错误
then
echo $error
#删除本地tag
git tag -d $tag
#删除远端tag
git push origin :refs/tags/$tag
fi
git tag $tag
git push --tags
#本地验证库信息 --verbose
pod lib lint --allow-warnings
#验证远端信息
pod spec lint --private
#推送到私有库
pod repo push localSpec MyLib.podspec
- CocoaPods.podspec编辑备份
#
# Be sure to run `pod lib lint MyLib.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 https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'MyLib'
s.version = '0.2.1'
s.summary = 'MyLib.'
# 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
第一次的私有库打发第三方
DESC
s.homepage = 'https://gitee.com/TianTianKaiFa/DemoLib'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '[email protected]' => '[email protected]' }
s.source = { :git => 'https://gitee.com/TianTianKaiFa/DemoLib.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '9.0'
s.subspec 'Categorys' do |ss|
ss.source_files = 'MyLib/Classes/Categorys/*'
end
s.subspec 'Components' do |ss|
ss.source_files = 'MyLib/Classes/Components/**/*'
end
s.subspec 'Config' do |ss|
ss.source_files = 'MyLib/Classes/Config/*'
end
#s.source_files = 'MyLib/Classes/**/*'
# s.resource_bundles = {
# 'MyLib' => ['MyLib/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end