美文网首页iOS程序猿iOS高级开发技术AppWorker
把上传Github的代码添加Cocoapods支持

把上传Github的代码添加Cocoapods支持

作者: _maomao | 来源:发表于2018-09-30 15:24 被阅读44次

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

    2, 用github客户端clone下来这个项目,编写代码。

    3.编写测试完成代码之后,将代码上传到github。

    4.将代码发布release版本 输入版本号

    接下来就是重点了,让自己的代码可以通过pod管理,别人使用起来更加方便

    1.进入项目代码目录

    $ cd  /Users/apple/Desktop/test

    2.创建一个podspec文件 此文件用来配置仓库代码环境 ,命令:

    $ pod spec create test    

    3.编辑 podspec文件,通过2步骤生成的文件 已经写好了默认的配置,里面会有详细的注释(英文的),需要进行一些修改,可以直接用xcode打开编辑,也可以用txt文档。下面用中文注释的配置 更具具体情况修改

    Pod::Spec.newdo|s|

    #pod名 (test 是pod名字 别人pod的时候需要填的那个)

      s.name         = "test"

    #版本 这里的版本号需要和github代码release版本号一致

      s.version      = "1.0.1"

    #简介

      s.summary      = "测试"

    #LICENSE

    s.license = "MIT (LICENSE)"

      # s.license      = { :type => "MIT", :file => "FILE_LICENSE" }

    #代码主页

    s.homepage = "https://github.com/wangyin1/YINMapping"

    #描述

      s.description  =  "测试描述"

      s.platform     = :ios

    #代码git地址

      s.source       = { :git => "https://github.com/wangyin1/YINMapping.git", :tag =>"1.0.0"}

    #pod需要下载的代码文件 Classes是文件名 和podspec同级 ,也可以自定义文件名

      s.source_files  = "Classes", "Classes/**/*.{h,m}"

    #资源文件

      s.exclude_files = "Classes/Exclude"

      s.framework  = "UIKit"

      # s.frameworks = "SomeFramework", "AnotherFramework"

      # s.library   = "iconv"

      # s.libraries = "iconv", "xml2"

      # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

      #

      #  If your library depends on compiler flags you can setthem inthe xcconfig hash

      #  where they will only apply to your library. If you depend on other Podspecs

      #  you can includemultiple dependencies to ensure it works.

      # s.requires_arc = true

      # s.xcconfig = { "HEADER_SEARCH_PATHS"=> "$(SDKROOT)/usr/include/libxml2"}

    #依赖的第三方 如果有多个 写多次

      # s.dependency "JSONKit", "~> 1.4"

    end

    4.保存pod配置文件之后,进行校验 

    $ pod spec lint

    如果终端提示 (but you can use `--allow-warnings` to ignore them).

    1$ pod spec lint --allow-warnings

    如果验证不通过,会有详细的ERROR和WARING提示,根据提示依次解决,然后回到第3步重新来一遍。

    5.podspec校验通过之后,接下来我们需要将这个文件提交到pod仓库,其他人才能search 到我们的项目。 

    如果你是第一次提交pod(自己没有pod仓库,不是github,这两者不是同一个东西,pod仓库只是保存的一些配置,代码在github),需要先执行这个命令注册一个仓库:

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

    如果有仓库,跳过第一步

    2.将配置提交到trunk

     pod trunk push --allow-warnings 

    (注意:)刚提交后项目用pod search命令会搜不到,因为本地的索引没有更新,使用下面命令删除索引文件

    rm ~/Library/Caches/CocoaPods/search_index.json

    最后pod search 命令搜到自己的项目,大功告成

    相关文章

      网友评论

        本文标题:把上传Github的代码添加Cocoapods支持

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