本文源自本人的学习记录整理与理解,其中参考阅读了部分优秀的博客和书籍,尽量以通俗简单的语句转述。引用到的地方如有遗漏或未能一一列举原文出处还望见谅与指出,另文章内容如有不妥之处还望指教,万分感谢。
制作远程私有库分为以下几个步骤:
创建私有 Git 远程仓库;
创建私有 CocoaPods 远程索引库;
创建 Pod 所需要的项目工程文件,并上传到 Git 远程私有库;
验证 podspec 描述文件;
向私有 CocoaPods 远程索引库提交 podspec 描述文件;
使用 Pod 库;
快速开整:
cd /Users/mac/Desktop/XXEncryptKitCes
pod lib create XXEncryptKit
cd /Users/mac/Desktop/XXEncryptKitCes/XXEncryptKit/Example
pod install
cd /Users/mac/Desktop/XXEncryptKitCes/XXEncryptKit
git add .
git commit -m '第一次提交0.1.0'
git remote add origin https://gitee.com/alvinsunny/XXEncryptKit.git
git push origin master -f
git tag 0.1.1
git push --tags
git pull origin master --allow-unrelated-histories
#创建本地私有索引库
cd .cocoapods/repos
#pod repo add 索引库名字 索引库地址
pod repo add XXEncryptKitSpec https://gitee.com/alvinsunny/XXSpecs.git
#创建完成
pod lib lint XXEncryptKitSpec.podspec --allow-warnings
或
pod lib lint xxx.podspec --verbose --use-libraries --allow-warnings --no-clean --sources='http://code.gome.inc/gitlab/MBPrivatePods/MBSpecs.git,https://github.com/CocoaPods/Specs'
pod repo push XXEncryptKitSpec XXEncryptKit.podspec --allow-warnings
Validating spec
-> XXEncryptKit (0.1.1)
Updating the `XXEncryptKitSpec' repo
Adding the spec to the `XXEncryptKitSpec' repo
- [Add] XXEncryptKit (0.1.1)
Pushing the `XXEncryptKitSpec' repo
执行过程
#1. 创建命令 ProjectName:你的工程名
pod lib create ProjectName
#2. 选择编程语言
What language do you want to use?? [ Swift / ObjC ]
> Objc
#3. 在你的项目中是否创建一个demo工程,为了方便测试,我选择了Yes
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
#4. 测试框架选择哪一个
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
#5. 要不要做视图测试
Would you like to do view based testing? [ Yes / No ]
> Yes
#6. 类前缀名
What is your class prefix?
> XSD
创建完项目会自动打开,项目目录结构如下:
├── XXEncryptKit
│ ├── Assets
│ └── Classes
│ └── ReplaceMe.m
├── XXEncryptKit.podspec
├── Example
├── LICENSE
├── README.md
└── _Pods.xcodeproj -> Example/Pods/Pods.xcodeproj
把
ReplaceMe.m
替换为自己的代码在Example 目录下
pod install
即可使用
编辑CocoaPods的配置文件 -- XXEncryptKit.podspec
要求:
代码版本要与项目的tag对应
s.homepage和s.source 必须正确
不可使用中文标点
s.ios.deployment_target 项目最低版本号必须和Xcode 中一致
cd 到模板目录(最外部) 验证 podspec 文件:
pod lib lint --allow-warnings
--allow-warnings:忽略警告
项目发布
1、 终端移到该项目文件下执行git的相关命令
2、在gitHub创建git私有库
3、在终端执行git提交命令
详细过程
#1. 开发玩🤩代码cd到工程目录的Example文件
localhost:BasisProject mac$ cd /Users/mac/Desktop/XSDLoading/Example
#1.1 pod install
localhost:Example mac$ pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
#1.2 cd 到工程目录
ocalhost:BasisProject mac$ cd /Users/mac/Desktop/XSDLoading
#2. 提交到本地缓冲区
localhost:XSDLoading mac$ git add .
#3. 描述信息
localhost:XSDLoading mac$ git commit -m '第一次提交0.1.0'
[master b0ecfb1] 第一次提交0.1.0
~~~~~~~~~~
create mode 100644 Example/Pods/Target Support Files/XSDLoading/XSDLoading-Info.plist
create mode 100644 Example/Pods/Target Support Files/XSDLoading/XSDLoading-
delete mode 100644 XSDLoading/Classes/ReplaceMe.m
create mode 100755 XSDLoading/Classes/UIImage+XXXImageParser.h
create mode 100755 XSDLoading/Classes/UIImage+XXXImageParser.m
#4. 连接远程仓库
localhost:XSDLoading mac$ git remote add origin https://gitee.com/alvinsunny/XSDLoading.git
#5. 强制提交
localhost:XSDLoading mac$ git push origin master -f
#git push -f origin master//将本地库的代码推到远程库
#git push --tags//将本地创建的tag推到远程库
Enumerating objects: 87, done.
Counting objects: 100% (87/87), done.
Delta compression using up to 8 threads
Compressing objects: 100% (78/78), done.
Writing objects: 100% (87/87), 32.17 KiB | 2.14 MiB/s, done.
Total 87 (delta 23), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/alvinsunny/XSDLoading.git
+ 14bfa1a...b0ecfb1 master -> master (forced update)
#6. 这里的tag就是弄个版本记录
localhost:XSDLoading mac$ git tag 0.1.0
#7. 提交tag
localhost:XSDLoading mac$ git push --tags
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/alvinsunny/XSDLoading.git
* [new tag] 0.1.0 -> 0.1.0
#git pull origin master
localhost:XSDLoading mac$ git pull origin master --allow-unrelated-histories
From https://gitee.com/alvinsunny/XSDLoading
* branch master -> FETCH_HEAD
Already up to date.
#8. 添加spec到远程仓库
localhost:XSDLoading mac$ pod repo add XSDLoadingSpec https://gitee.com/alvinsunny/PTBSpecs.git
Cloning spec repo `XSDLoadingSpec` from `https://gitee.com/alvinsunny/PTBSpecs.git`
#9. 验证 .podspec 文件
localhost:XSDLoading mac$ pod lib lint XSDLoading.podspec --allow-warnings
-> XSDLoading (0.1.0)
- WARN | summary: The summary is not meaningful.
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Building targets in parallel
XSDLoading passed validation.
验证成功!!!!!! 😁
#10. 推送 .podspec文件到远端
localhost:XSDLoading mac$ pod repo push XSDLoadingSpec XSDLoading.podspec --allow-warnings
Validating spec
-> XSDLoading (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 | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
Updating the `XSDLoadingSpec' repo
Adding the spec to the `XSDLoadingSpec' repo
- [Add] XSDLoading (0.1.0)
Pushing the `XSDLoadingSpec' repo
localhost:XSDLoading Mac$
成功!!!!!!!!😁😁😁😁😁😁😁😁😁
集成到主项目
platform :ios, '9.0'
source 'https://gitee.com/alvinun/PTBSpecs.git'
target 'XXXMainUIKit' do
pod 'XSDLoading'
end
拉取项目
#pod install --repo-update
[localhost:XXMainUIKit mac$ pod install --repo-update
Updating local specs repositories
$ /usr/bin/git -C /Users/mac/.cocoapods/repos/gitee-alvinsunny-ptbspecs fetch
origin --progress
Analyzing dependencies
Downloading dependencies
Installing XSDLoading (0.1.0)
Generating Pods project
Integrating client project
Pod installation complete! There are 3 dependencies from the Podfile and 3 total pods installed.
localhost:XXMainUIKit Mac$
常见git命令
git init #//初始化
git status #//查看状态
git add . #//添加文件到缓冲区
git commit -m "描述" #//从缓冲区提交代码到仓库
git tag -a '0.0.1' -m '描述' #//添加tag
git tag #//查看tag
git tag -d '0.0.1' #//删除tag
git remote add origin https://github.com/xxx.git #//关联本地仓库和远程仓库。
git push -f origin master #//将本地库的代码推到远程库
git push --tags #//将本地创建的tag推到远程库
git push origin :0.0.1 #//删除tag
# 安装并设置 git,全局配置用户名邮箱配置,也可以在项目根目录对单个仓库进行设置,去除--global参数即可
git config --global user.name "Yours Name"
git config --global user.email "xxx@xx.com"
git config --list
常用分支管理命令
git clone xxx (xxx为刚刚复制的仓库链接)
# 查看所有分支
git branch -a
# 新建分支
git branch xxx (xxx填写你的分支名称)
# 切换到某一分支
git checkout xxx (xxx填写要切换的分支名称)
# 提交代码到指定分支
git push origin xxx (xxx为要提交代码的分支名称)
# 删除本地分支和远程分支(注意删除前先,确定自己不在要删除的分支上)
# 1. 切换到要操作的项目文件夹
cd ProjectPath
# 2. 查看项目分支(包括本地和远程)
git branch -a
# 3. 删除本地分支
git branch -d 分支名
# 4. 删除远程分支
git push origin –delete 分支名
# 5. 查看删除后的分支
git branch -a