创建公有的Cocopods库
1、注册cocopods
启动终端terminal:
$ pod trunk register GitHub_email 'user_name' --verbose
GitHub_email:github邮箱,user_name:用户名。
稍等。。。
[!] Please verify the session by clicking the link in the verification email that has been sent to xxx@qq.com
此时cocopods会给我的邮箱发送一封确认邮件,登录邮箱进行确认。
确认完成之后,在终端:
$ pod trunk me
会看到账号的基本信息。
2、创建Git仓库
在 GitHub 上创建一个公开项目,项目中必须包含这几个文件
-
LICENSE
:开源许可证 -
README.md
:仓库说明 -
你的代码
-
仓库名.podspec
: CocoaPods 的描述文件,这个文件非常重要1.
LICENSE
、README.md
这两个文件在创建Git仓库的时候勾选。2.本地Git创建
-
创建文件夹目录:例如ZXMTBButton。
-
终端进入目录下,执行
$ git init
Initialized empty Git repository in /Users/zxm/Desktop/ZXMTBButton/.git/,将文件置于Git管理下。
-
自己的代码放在目录下
-
$ git add . #添加所有文件
$ git commit -m 'proj init' #提交到缓存区
$ git remote add origin Git仓库地址 #关联远程仓库地址
$ git pull --rebase origin master #远程仓库中有 LICENSE、README.md文件,将其更新带本地,必须。
$ git push -u origin master #将本地文件推送到远程仓库
3.创建.podspec
.podspec
是用 Ruby 的配置文件,描述你项目的信息。
在你的仓库目录下,使用终端命令创建
$ pod spec create ZXMTBButton #创建.podspec
使用xcode打开ZXMTBButton.podspec文件,进行必要编辑:
1、 s.name = "ZXMTBButton" #可以用于pod search
s.version = "0.0.1" #pod search显示的版本号
s.summary = "Custom Button summary."
2、s.description = <<-DESC
Custom Button description。 #这里可以添加描述(必须添加)
DESC
3、s.homepage = "https://github.com/zxmios/ZXMTBButton" #需要修改
4、s.license = "MIT" #协议类型
5、s.author = { "Xianming Zhou" => "" } #可以不修改
6、s.platform = :ios, "8.0"#必须放开
7、s.source = { :git => "https://github.com/zxmios/ZXMTBButton.git", :tag => "#{s.version}" } #需要修改
8、s.source_files = "ZXMTBButton/*.{h,m}" #表示ZXMTBButton目录下所有.h、.m文件
9、s.frameworks = "UIKit", "Foundation" #支持的框架、必须(否则验证时报错)
10、s.requires_arc = true # 是否启用ARC、必须
11、s.dependency "JSONKit", "~> 1.4" #依赖库(可以没有)
需要注意:s.summary和s.description中的描述不能一样,否则验证无法通过。
修改完成:就可以进行最重要的验证了:
$ pod lib lint
[!] ZXMTBButton did not pass validation, due to 1 warning (but you can use
--allow-warnings
to ignore it).
You can use the--no-clean
option to inspect any issue.
如果出现以上错误,根据提示执行:
$ pod lib lint --allow-warnings
-> ZXMTBButton (0.0.1)
ZXMTBButton passed validation.
即可,其他类似错误,根据提示信息采用相应的处理方式。
验证成功后,将仓库提交到远程,然后可以给仓库打上标签并将标签也推送到远程。
3、给仓库打标签
标签相当于将你的仓库的一个压缩包,用于稳定存储当前版本。标签号与你在 s.version = "0.0.1"
的版本号一致0.0.1
,pod search 搜索显示的版本号。
$ git tag -a 0.0.1 -m '版本0.0.1'
$ git push origin --tags
To https://github.com/zxmios/ZXMTBButton.git
*[new tag] 0.0.1 -> 0.0.1
此时,远程仓库中tags就有了0.0.1标签。
4、发布.podspec
万里长征总算到了最后一步,发布ZXMTBButton.podspec。
$ pod trunk push ZXMTBButton.podspec
Updating spec repo
master
Validating podspec
🎉 Congrats
🚀 ZXMTBButton (0.0.1) successfully published
📅 May 1st, 22:08
🌎 https://cocoapods.org/pods/ZXMTBButton
👍 Tell your friends!
发布成功!
可以访问https://cocoapods.org/pods/ZXMTBButton查看我们的仓库信息了。
最后的最后:删除~/Library/Caches/CocoaPods目录下的search_index.json文件
rm ~/Library/Caches/CocoaPods/search_index.json
再次使用,pod search ZXMTBButton就可以搜索到我们的库了。
Custom Button summary.
pod 'ZXMTBButton', '~> 0.0.1'
- Homepage: https://github.com/zxmios/ZXMTBButton
- Source: https://github.com/zxmios/ZXMTBButton.git
- Versions: 0.0.1 [master repo]