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#设置taggit 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 descriptionSTTPrivateRepo 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 descriptionUpdating the `STTPrivateRepo' repoAdding 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.gitgit 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/
