创建自己的CocoaPods库

来源:互联网 发布:网络设置(2g) 编辑:程序博客网 时间:2024/05/18 11:40

创建自己的CocoaPods库

前期准备:

  1. 准备好自己的代码库,本文以github上的代码库为例,可参考作者的工程:LYCopyLabel。

  2. 注册trunk(已注册过的请跳过):

    // 升级pods至最新版本$ sudo gem install cocoa pods// 进行注册 邮箱和GitHub用户名字$ pod trunk register example@xxx.com 'GithubUserName' --verbose // 根据提示点击邮箱链接进行验证 完成注册
  3. 查看注册是否成功:

     $ pod trunk me //返回如下表示注册成功- Name:     GithubUserName- Email:    example@xxx.com- Since:    May 13th, 11:19- Pods:     None- Sessions:

正式开始

  1. 创建.podspec仓库文件:

    //创建仓库文件$ pod spec create LYCopyLabel// 返回如下Specification created at LYCopyLabel.podspec
  2. 编辑.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     = :ioss.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"
  3. 使用 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
  4. 推送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!
  5. 使用pods search搜索自己的pod库验证下,大功告成。

    $ pod search LYCopyLabel// 返回如下,大功告成。-> LYCopyLabel (1.0.1)Sub Class of UILabel to make the label enable to be copyed when long pressedpod 'LYCopyLabel', '~> 1.0.1'- Homepage:https://github.com/liuyang20091130/LYCopyLabel- Source: https://github.com/liuyang20091130/LYCopyLabel.git- Versions: 1.0.1 [master repo]
0 0
原创粉丝点击