创建自己的CocoaPods库
前期准备:
准备好自己的代码库,本文以github上的代码库为例,可参考作者的工程:LYCopyLabel。
注册trunk(已注册过的请跳过):
// 升级pods至最新版本 $ sudo gem install cocoa pods // 进行注册 邮箱和GitHub用户名字 $ pod trunk register example@xxx.com 'GithubUserName' --verbose // 根据提示点击邮箱链接进行验证 完成注册
查看注册是否成功:
$ pod trunk me //返回如下表示注册成功 - Name: GithubUserName - Email: example@xxx.com - Since: May 13th, 11:19 - Pods: None - Sessions:
正式开始
创建
.podspec
仓库文件://创建仓库文件 $ pod spec create LYCopyLabel // 返回如下 Specification created at LYCopyLabel.podspec
编辑
.podspec
文件,可以根据内容提示自己编辑,也可以参考比较知名的三方库的该文件进行编辑。$ vim LYCopyLabel.podspec //编辑文本 Pod::Spec.new do |s| s.name = "LYCopyLabel" s.version = "1.0.1" s.summary = "Sub Class of UILabel to make the label enable to be copyed when long pressed" s.homepage = "https://github.com/liuyang20091130/LYCopyLabel" s.license = 'MIT' s.author = { "liuyang20091130" => "example@xxx.com" } s.platform = :ios s.platform = :ios, "5.0" s.source = { :git => "https://github.com/liuyang20091130/LYCopyLabel.git", :tag => "#{s.version}" } s.source_files = "CopyLabel/LYCopyLabel/*.{h,m}" s.public_header_files = "CopyLabel/LYCopyLabel/*.h"
使用
pod lib lint
验证.podspec
文件的正确性。若出现错误需根据提示执行第2步进行修改。//执行 pod lib lint LYCopyLabel.podspec //正确返回 -> LYCopyLabel (1.0.1) LYCopyLabel passed validation.
有可能出现的提示:
- WARN | source: The version should be included in the Git tag.
,则需要给git添加tag。tag要与.podspec
文件中s.source :tag
相同。$ git tag '1.0.1' $ git push --tags
推送pod代码库到远程仓库,耐心等待返回。
//执行 pod trunk push LYCopyLabel.podspec //返回如下表示成功 -> LYCopyLabel (1.0.1) Sub Class of UILabel to make the label enable to be copyed when long pressed pod 'LYCopyLabel', '~> 1.0.1' - Homepage: https://github.com/liuyang20091130/LYCopyLabel - Source: https://github.com/liuyang20091130/LYCopyLabel.git - Versions: 1.0.1 [master repo] ESCOC -------------------------------------------------------------------------------- �� Congrats �� LYCopyLabel (1.0.1) successfully published �� May 13th, 11:59 �� https://cocoapods.org/pods/LYCopyLabel �� Tell your friends!
使用
pods search
搜索自己的pod库验证下,大功告成。$ pod search LYCopyLabel // 返回如下,大功告成。 -> LYCopyLabel (1.0.1) Sub Class of UILabel to make the label enable to be copyed when long pressed pod 'LYCopyLabel', '~> 1.0.1' - Homepage:https://github.com/liuyang20091130/LYCopyLabel - Source: https://github.com/liuyang20091130/LYCopyLabel.git - Versions: 1.0.1 [master repo]