1. 创建远程仓库
以Git
代码托管平台Gitee为案例
登录Gitee
账号,选择新建仓库
创建私有仓库STTPrivateRepo
创建成功后,获得远程仓库地址
2. 搭建本地组件
使用终端,搭建本地组件
pod lib create STTPrivateRepo
-------------------------
//对模块进行以下配置:
//工程类型
What platform do you want to use?? [ iOS / macOS ]
> iOS
//开发语言
What language do you want to use?? [ Swift / ObjC ]
> ObjC
//创建App测试项目
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
//提供frameworks的测试
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
//提供测试文件
Would you like to do view based testing? [ Yes / No ]
> No
//设置前缀
What is your class prefix?
> STT
找到.podspec
文件,对homepage
和source
进行配置
homepage
:没有要求,但必须可以访问source
:Gitee
上创建的远程仓库地址
工程下的Classes
目录,自动生成ReplaceMe.m
文件。可将其删除,将真实代码文件拷贝至该目录下
使用终端,在工程下的Example
目录中,执行pod install
命令执行成功后,刚才拷贝的代码在项目中生效
3. 测试本地组件
搭建LGFramework
测试项目,在Podfile
中写入以下代码:
platform :ios, '9.0'
target 'LGFramework' do
# use_frameworks!
pod 'STTPrivateRepo', :path => '/Users/zang/Zang/Spark/LG/git_temp/STTPrivateRepo'
end
使用终端,在测试项目目录中,执行pod install
- 保证本地组件可以正常使用
4. 提交组件到远程代码库
使用终端,在组件目录下,执行以下命令:
#添加文件
git add .
#把代码提交到本地
git commit -s -m "首次提交"
#关联仓库
git remote add origin https://gitee.com/zangcrab/STTPrivateRepo.git
#把代码提交到远端仓库
git push origin master
设置tag
#版本号必须和.podspec文件中的版本号一致
git tag -m "初始版本" 0.1.0
#设置tag
git push --tags
查看.podspec
文件中的版本号
- 版本号,二者必须一致
命令执行成功后,在Gitee
远程仓库中,可以看到代码提交后的变化
5. 提交podspec
索引文件
使用终端,在组件目录下,执行以下命令:
pod lib lint --allow-warnings
-------------------------
-> STTPrivateRepo (0.1.0)
- WARN | summary: The summary is not meaningful.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Building targets in parallel
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | xcodebuild: note: Build preparation complete
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Analyzing workspace
- NOTE | [iOS] xcodebuild: note: Constructing build description
STTPrivateRepo passed validation.
验证通过之后,提交索引文件到远程索引库
#pod repo push 本地索引库 索引文件名
pod repo push STTPrivateRepo STTPrivateRepo.podspec --allow-warnings
-------------------------
Validating spec
-> STTPrivateRepo (0.1.0)
- WARN | summary: The summary is not meaningful.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Building targets in parallel
- NOTE | xcodebuild: note: Using codesigning identity override: -
- NOTE | xcodebuild: note: Build preparation complete
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Analyzing workspace
- NOTE | [iOS] xcodebuild: note: Constructing build description
Updating the `STTPrivateRepo' repo
Adding the spec to the `STTPrivateRepo' repo
- [Update] STTPrivateRepo (0.1.0)
Pushing the `STTPrivateRepo' repo
6. 使用组件
延用LGFramework
测试项目,在Podfile
中写入以下代码:
platform :ios, '9.0'
target 'LGFramework' do
# use_frameworks!
pod 'STTPrivateRepo', :git => 'https://gitee.com/zangcrab/STTPrivateRepo.git'
end
使用终端,在测试项目目录中,执行pod install
成功导入STTPrivateRepo
组件
7. 备注
7.1 github
使用access tokens
在关联仓库和使用组件时,需要使用access tokens
关联仓库:
#关联仓库
#git remote add origin https://[access tokens]@github.com/ZangCrab/STTPrivateRepo.git
git remote add origin https://ghp_xxxxx@github.com/ZangCrab/STTPrivateDemo.git
使用组件:
platform :ios, '9.0'
target 'LGFramework' do
# use_frameworks!
pod 'STTPrivateRepo', :git => 'https://ghp_xxxxx@github.com/ZangCrab/STTPrivateDemo.git'
end
7.2 remote origin already exists
如果本地代码已经关联其他仓库,再次关联时会报错
#关联仓库
git remote add origin https://gitee.com/zangcrab/STTPrivateRepo.git
-------------------------
fatal: remote origin already exists
此时需要解除之前的关联
git remote rm origin
7.3 其他
Git
配置多个SSH-Key
:https://gitee.com/help/articles/4229#article-header0
Git
常用命令:https://gitee.com/all-about-git
CocoaPods
指南:https://guides.cocoapods.org/