如何建立自己的公有pod

如果在开发过程中,想把自己封装的一些控件、分类打包以pod的形式供自己或团队使用,我们可以建立公有pod或者私有pod。

以下指示介绍如何打包公有pod供自己使用。

步骤 1.
前往githup建立库。

cocoapods.png

选择MIT 认证(得到cocopods的认证许可。)

接下来把你需要的上传的工具类放到目录下:


目录.png

步骤二:

创建.podspec文件。
LXUtils 是你新建库的名字。

pod spec create LXUtils

执行完上面的命令,会生成一个.podspec的文件。

可以编辑打开,我是通过webStorm打开的(不知道为什么,通过默认的编辑器打开后面进行spec文件验证的时候经常提示语法错误,所以建议还是通过工具打开吧):

最好还是根据里面的修改。切记tag选项前面必须添加v

s.name         = "LXUtils"
 s.version      = "0.0.1"
 s.summary      = "common tools on iOS."
s.description  = <<-DESC
                common tool and category on iOS
                   DESC
  s.homepage     = "https://github.com/liuxinixn/LXUtils"
s.license      = "MIT"
 s.author             = { "miss李" => "missli_211@163.com" }
s.platform     = :ios, "8.0"

s.source       = { :git => "https://github.com/liuxinixn/LXUtils.git", :tag => "v#{s.version}" }

s.source_files  = "LXUtils", "LXUtils/**/*.{h,m}"
s.framework  = "UIKit"
  s.requires_arc = true

修改好对应的选项之后,验证spec文件的合法性。

pod lib lint LXUtils.podspec
验证.png

步骤3.

绑定tag,然后发布。

git tag '0.0.1'  
git push --tags  
git push origin master

下面的命令需要你去邮箱进行验证

pod trunk register jiushu0228@163.com 'LXUtils'
pod trunk me

验证结果


邮箱验证.png

如果出现下面的问题:

[!] 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`.

执行echo "2.3" > .swift-version即可。

最后一步,发布spec到cocoapods

pod trunk push LXUtils.podspec

成功后如下:

zhongzhideMini:LXUtils chenergou$ pod trunk push LXUtils.podspec
Updating spec repo `master`

CocoaPods 1.3.0.beta.3 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.3.0.beta.3

Validating podspec
 -> LXUtils (0.0.1)

Updating spec repo `master`

CocoaPods 1.3.0.beta.3 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.3.0.beta.3


--------------------------------------------------------------------------------
 🎉  Congrats

 🚀  LXUtils (0.0.1) successfully published
 📅  November 8th, 02:45
 🌎  https://cocoapods.org/pods/LXUtils
 👍  Tell your friends!

补充

提交后需要等一段时间,如果搜不到试试下面的方法:
根据路径~/Library/Caches/CocoaPods/search_index.json找到这个json文件,然后删除即可。

重新'pod search LXUtils'

输出:Creating search index for spec repo 'master'.. Done!,稍等片刻就会出现所有带RxSwift字段的类库出现。

如何更新pod

1.升级版本

git tag 'v0.0.2'  
git push --tags  
git push origin master

2.更新到cocoapods

pod trunk push LXUtils.podspec

成功之后,如果搜索不到执行pod setup

总结

主要命令:

git tag 0.0.1   //打tag
git push --tags //推送tag到远程
git push origin master 
pod lib lint//验证spec文件的合法型
pod trunk push LXMUtils.podspec //推送spec

pod trunk register xxx@163.com 'userName' --verbose //每次注册新的仓库必须验证一次
pod trunk me//验证结果
git tag -d 0.0.1 //移除某个tag
git push origin :refs/tags/0.0.1 //远程移除某个tag

推荐文章 :http://www.cocoachina.com/articles/25864

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容