这里使用的代码托管平台是码云上创建。
操作步骤:
一、创建两个私有仓库
二、创建 spec repo
三、创建pod所需项目工程文件,并上传到pod远程私有库
四、向私有的spec Repo远程仓库中提交podspec
五、使用创建的私有pod库
六、私有库更新
一、创建两个私有仓库
一个存放repo,一个存放pod所需项目工程文件
repo库
pod库
注意:
1、选择私有
2、repo库默认选择初始化
3、pod库默认不初始化
二、创建 spec repo
1、查看本地仓库
pod repo
2、添加远程repo库
pod repo add 仓库名 仓库SSH(HTTPS)地址
pod repo add hftestrepo https://gitee.com/****/hftest-repo.git
添加之后,再次执行pod repo 查看是否成功
还可以 通过 ~/.cocoapods/repos 到对应路径下查看
三、创建pod所需项目工程文件,并上传到pod远程私有库
1、设定一个目标文件并创建私有库
cd 目标文件夹
pod lib create HFTestKit (HFTestKit私有仓库名)
创建成功之后会自动打开上述工程文件。
1、pod lib create 创建成功的工程
2、选项中勾选得到示例工程
3、索引文件
4、自定义pod库代码位置
索引文件,相关字段有解释,可以查看cocoapods官方文档了解更多。
Pod::Spec.new do |s| s.name = 'HFTestKit' s.version = '0.1.0' s.summary = 'A short description of HFTestKit.' # 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 TODO: Add long description of the pod here. DESC s.homepage = 'https://gitee.com/****/hftest-kit' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { '****' => '****' } s.source = { :git => 'https://gitee.com/****/hftest-kit.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>' s.ios.deployment_target = '10.0' s.source_files = 'HFTestKit/Classes/**/*' # s.resource_bundles = { # 'HFTestKit' => ['HFTestKit/Assets/*.png'] # } # s.public_header_files = 'Pod/Classes/**/*.h' # s.frameworks = 'UIKit', 'MapKit' # s.dependency 'AFNetworking', '~> 2.3' end
homepage:pod远程私有仓库地址,不带.git
source:pod远程私有仓库地址,带.git
注意修改为创建好的远程私有pod库地址。
2、验证本地仓库
先cd 到HFTestKit路径下,然后执行
pod lib lint HFTestKit.podspec --allow-warnings
建议加—allow-warnings 因为有警告会导致失败。如果你能都解决警告也可以放开。
得到 HFTestKit passed validation. 继续执行。
3、在Example工程中验证
增加一些类
然后到Example工程下,执行
pod install
打开Example工程
4、将本地pod库上传到远程私有pod库
cd 到 HFTestKit路径下
git add .git
git commit -m "add manager"git remote add origin https://gitee.com/lisa_1900/hftest-kit.git
git push https://gitee.com/****/hftest-kit.git main
注意:
5、指定tag
git tag 0.1.0 #这里的版本号必须和podspec中的s.version值相同
git push --tags
四、向私有的spec Repo远程仓库中提交podspec
hftestrepo是本地私有索引库。
cd 到HFTestKit文件夹
pod repo push hftestrepo HFTestKit.podspec --allow-warnings --use-libraries
//--allow-warnings:加上该选项,验证时如果有警告会忽略警告,否则无法验证通过
//--use-libraries:如果依赖了静态库就需要加上该选项
远程索引库
本地索引库
创建成功。
五、使用创建的私有pod库
新建一个工程
Podfile文件内
use_frameworks!
platform :ios, '10.0'
# 远程私有库
source 'https://gitee.com/lisa_1900/hftest-repo.git'
target 'HFRepoDemo' do
pod 'HFTestKit'
end
执行pod install
#import "ViewController.h"
#import <hftestkit/HFTestUtil.h>
#import <hftestkit/HFTestManager.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
[HFTestUtil hfUtil];
[HFTestManager hfManagerMethods];
}
@end
可以正常使用。
因为我们的仓库都是私有的,所以在哪里需要安装的话,需要有对这两个私有仓库的访问权限就好,发布公有的类似,只是发布到了官方的 podspec 仓库。
六、私有库更新
1、修改xxx/xxx/Classes文件夹下对应的库文件
2、更新测试工程的Pod库文件: pod update --no-repo-update
3、更新xxx.podspec文件的配置信息, 版本号一定要改
4、提交代码到远程仓库: git push
5、更新tag标签:git tag -a 0.2.0 -m "0.1.0"git push --tags
6、更新远程和本地的私有索引库: pod repo push MyRepo XXX.podspec --allow-warnings注意:
--no-repo-update:安装pods之前不要更新pods仓库可以install、pod的速度更快一些。
1、修改xx/xx/Classes文件夹下的类:新增几个类
2、Example 工程 执行
pod update --no-repo-update
3、修改podspec文件的配置信息, 版本号一定要改
4、代码提交修改并推送到远程私有pod库
git add .
git commit -m "commit message"
git push
5、更新tag,并推送至远程私有库
git tag 0.2.1 #这里的版本号必须和podspec中的s.version值相同
git push --tags
6、更新远程和本地的私有索引库
pod repo push hftestrepo HFTestKit.podspec --allow-warnings --use-libraries
pod repo push 本地私有索引库名称 XXX.podspec
注意:
多操作几次,就可以熟练掌握的。