創建自己的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" => "[email protected]" } 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]