一、 创建2个私有仓库
1. 在Gitee
中创建组件仓库(私有)
作用:存放组件代码
https://gitee.com/yuanzhiying/information-module.git
2. 在Gitee
中创建组件管理仓库(私有)
作用:管理所有组件
https://gitee.com/yuanzhiying/manager-module.git
二、远程组件管理仓库添加到本地
1. 进入本地的.cocoapods/repos
目录
$ cd .cocoapods/repos
2. 将远程组件管理仓库添加到本地的仓库中
$ pod repo add ManagerModule https://gitee.com/yuanzhiying/manager-module.git
三、创建组件
1. 进入桌面目录,创建InformationModule
$ cd Desktop
$ pod lib create InformationModule
2. 根据提示进行选择:
3. 创建成功,自动打开项目。
四、配置组件项目
1. 进入项目的Example
中,执行pod install
$ cd InformationModule/Example
2. 修改InformationModule.podspec
如下:
3. 修改项目的Swift
版本
五、提交组件项目到仓库
$ cd Desktop/InformationModule
$ git status
$ git add .
$ git commit -m '提交资讯组件'
$ git remote add origin https://gitee.com/yuanzhiying/information-module.git
$ git pull origin master --allow-unrelated-histories
...
解决LICENSE文件冲突
...
$ git status
$ git add .
$ git commit -m '解决冲突'
$ git branch --set-upstream-to=origin/master master
$ git pull
$ git push origin master
六、打tag,并提交tag到远程仓库
根据podspec
中版本打tag,并提交tag到远程仓库
$ git tag -a 0.1.0
填写tag描述
$ git push --tags
七、验证podspec有效性并提交
pod lib lint和pod spec lint区别: pod lib lint = local, pod spec lint = local/remote pod lib lint: Will lint your pod locally, and will just ensure that you provided everything properly to create your pod. But it will not be enough to validate your pod, Only pod spec lint will. pod spec lint: Will lint your pod anywhere. By that I mean that you can have your pod source code up on GitHub, for example, and it will lint. If the pod spec lint returns without errors, you can push the linted pod up to Cocoapods.
1. 使用:$ pod spec lint InformationModule.podspec
$ pod spec lint InformationModule.podspec -> InformationModule (0.1.0) - WARN | url: The URL (https://gitee.com/yuanzhiying/information-module) is not reachable. - 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 - NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App') Analyzed 1 podspec. [!] The spec did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
https://gitee.com/yuanzhiying/information-module
是私有仓库,访问不到,在命令后加上--allow-warnings
。
2. 使用:$ pod spec lint InformationModule.podspec --allow-warnings
复制代码
$ pod spec lint InformationModule.podspec --allow-warnings
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb:229: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777 -> InformationModule (0.1.0) - WARN | url: The URL (https://gitee.com/yuanzhiying/information-module) is not reachable. - 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 - NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App') Analyzed 1 podspec. InformationModule.podspec passed validation.
验证通过。
3. 将资讯组件提交到管理组件的本地和远程仓库中
$ pod repo push ManagerModule InformationModule.podspec
本地仓库:
远程仓库:
pods中搜索:pod search InformationModule
八、组件的更新和维护
1. 添加新的文件到Classes
文件夹下,实现简单的代码,进入Example
目录,执行pod install
,新的文件会出现在Pods
里。
2. 修改InformationModule.podspec
中s.version
为0.1.1
3. 提交新代码到组件仓库里
$ cd Desktop/InformationModule
$ git status
$ git add .
$ git pull
$ git push
4. 打新的tag
$ git tag -a 0.1.1
填写tag描述
$ git push --tags
5. 验证podspec
文件
$ pod spec lint InformationModule.podspec --allow-warnings
验证通过。
6. 将资讯组件提交到管理组件的本地和远程仓库中
$ pod repo push ManagerModule InformationModule.podspec
九、组件的使用
1. 新建测试项目,并添加pods
支持
2. PodFile
中添加资讯组件模块
platform :ios, '9.0'
use_frameworks!
source 'https://gitee.com/yuanzhiying/manager-module.git'
target 'TestDemo' do
pod 'InformationModule', '~> 0.1.1'
end
注意:
此处要填写的是组件管理仓库的地址,如果填错成了组件的地址,会爆出以下错误:
[!] An unexpected version directory
Classes
was encountered for the/Users/yuanzhiying/.cocoapods/repos/gitee-yuanzhiying-information-module/InformationModule
Pod in theInformationModule
repository.
3. 更新本地的仓库
$ pod repo update
4. 执行pod install
,成功
5. 项目中使用
导入资讯组件,并使用
如果找不到模块或模块的方法,clean
项目并Command + B
编译项目.
作者:xmb
链接:https://juejin.cn/post/6989905586745786381/
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。