美文网首页iOS 大神之路iOSiOS 宝典
让自己的开源项目支持CocoaPods

让自己的开源项目支持CocoaPods

作者: X先生_vip | 来源:发表于2016-01-29 20:35 被阅读2114次
    一、让自己的开源项目支持CocoaPods

    <br />
    HZCountDownBtn 是我为测试的时候创建的一个倒计时的按钮,以它为例子!

    1.在github上创建一个HZCountDownBtn,重要:记得选择开源协议 (MIT)

    2.将HZCountDownBtn clone到自己的工作目录

    1. cd到当前目录
    $ cd HZCountDownBtn
    

    4.创建一个podspec文件,命令:

    $ pod spec create HZCountDownBtn
    

    5.编辑 podspec文件,这里是用vim打开的,命令:

    $ vim HZCountDownBtn.podspec
    

    6.创建之后会自动生成一个模板,里面会有详细的注释,我们只需要按需要修改这个文件即可,下边这个是测试的时候我编辑的 (如果需要更更多的配置 可以参考别的开源项目的podspec文件):

    Pod::Spec.new do |s|
      s.name     = 'HZCountDownBtn' 
      s.version  = '1.2' 
      s.license  = "MIT"  //开源协议
      s.summary  = 'This is a countdown button' //简单的描述 
      s.homepage = 'https://github.com/xingxianqing/HZCountdownBtn' //主页
      s.author   = { 'XianQing Xing' => '465578622@qq.com' } //作者
      s.source   = { :git => 'https://github.com/xingxianqing/HZCountdownBtn.git', :tag => "1.2" } //git路径、指定tag号
      s.platform = :ios 
      s.source_files = 'HZCountDownBtn/*'  //库的源代码文件
      s.framework = 'UIKit'  //依赖的framework
      s.requires_arc = true
    end
    

    7.创建tag,并推送到github,依次执行以下命令:

    $ git add .
    $ git commit -m "1.2"
    $ git tag 1.2
    $ git push --tags
    $ git push origin master
    

    8.验证podspec文件

    $ pod spec lint HZCountDownBtn.podspec
    
    • 如果验证不通过,会有详细的ERROR和WARING提示,根据提示依次解决,然后回到第7步重新来一遍。
      注意:在重新开始之前,我们要删除远程库的tag和本地的tag,命令如下:
    $ git tag -d 1.2                   //删除本地tag
    $ git push origin :refs/tags/1.2  // 删除远程库tag
    
    • 如果验证通过,如下:
    验证通过

    9.验证通过后,提交到CocoaPods。命令:

    pod trunk push HZCountDownBtn.podspec
    
    提交成功

    如果是第一次提交,需要先执行这个命令:

    $ pod trunk register 这里写邮箱 '这里起个名字' --description=' 这里写描述'
    

    执行完成之后,会给你的邮箱里发一封邮件,去邮箱点击链接之后,再重新执行第9步即可!
    这是cocopods的guides上的说明:
    http://guides.cocoapods.org/making/getting-setup-with-trunk.html

    cocopods guides

    10.提交完成后,就可以通过cocopods查找HZCountDownBtn了

    pod search HZCountDownBtn

    这样就可以进行使用了,能看到这里的应该都会使用cocopods了,不会的请移步到这里:http://www.jianshu.com/p/b5315bf42975

    <br />

    二、私有库

    <br />
    私有库只需要执行完第8步!
    在使用时,Podfile文件里面的写法和公有库也不一样 ,如下:

    pod 'ProjectName',:git=>"http://xxx.git"(把xxx替换为库的git地址)
    

    相关文章

      网友评论

      • 奥卡姆剃须刀:请教一下 按照你教程 在验证的时候出现以下错误怎么解决的 搞了好长时间了
        localhost:LLKit liushaohua$ pod spec lint LLKit.podspec

        -> LLKit (0.0.1)
        - ERROR | [OSX] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/liuniuliuniu/LLKit.git /var/folders/hk/2yx0cxfx13v7rk4kby621yx00000gn/T/d20170429-1612-1tqmq0f --template= --single-branch --depth 1 --branch 0.0.1

        Cloning into '/var/folders/hk/2yx0cxfx13v7rk4kby621yx00000gn/T/d20170429-1612-1tqmq0f'...
        warning: Could not find remote branch 0.0.1 to clone.
        fatal: Remote branch 0.0.1 not found in upstream origin
        ) during validation.

        Analyzed 1 podspec.

        [!] The spec did not pass validation, due to 1 error.
        [!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
        `echo "2.3" > .swift-version`.
        localhost:LLKit liushaohua$

      本文标题:让自己的开源项目支持CocoaPods

      本文链接:https://www.haomeiwen.com/subject/bemjkttx.html