美文网首页
上传自己的公开库至cocoapods

上传自己的公开库至cocoapods

作者: 自律改变现状 | 来源:发表于2018-05-23 18:46 被阅读0次



第一步 设置 podspec  文件

配置podspec文件

在此之前我们可以先在github上创建一个仓库(添加.gitignore、LICENESE、README.md文件会很方便)。 

然后我们将此仓库git clone下来。

创建podspec文件有2种方式,一种是通过终端输入指令创建,一种是找一个标准第三方库的podspec文件并在此基础上改改。

通过指令创建的podspec文件

创建指令:

pod spec create [NAME|https://github.com/USER/REPO]

//eg:

pod spec create 项目名.podspec

而我是用另一种方式创建的

touch 你的工程名.podspec。

终端 cd 到项目,编辑 podspec 文件

vim OCITButton.podspec

``` 

    Pod::Spec.new do |s|

    s.name = "OCITButton"

    s.version = "0.0.1"

    s.summary = "为了偷懒"

    s.description = "让按钮中的图片与标题更舒适放置"

    s.homepage = "https://github.com/19940524/OCITButton"

    s.license = { :type => 'MIT', :file => 'LICENSE' }

    s.author = { "19940524" => "@qq.com" }

    s.ios.deployment_target = '7.0'

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

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

    s.requires_arc = true    

    s.framework = "UIKit"

    end

``` 


第二步 给项目打一个tag

然后提交就OK

回到终端

验证下编辑过的  podspec 文件。

pod spec lint

验证失败!

- ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.

此错误的原因是没有找到匹配的文件。

解决方案:

手动创建文件,具体操作方法如下

终端输入:

open /Users/用户名/Library/Caches/CocoaPods/Pods/External/项目名/xxx

进入相应文件夹,创建文件夹与source_files文件路径对应,我这里是创建ITButton文件夹,我所开源的文件就是放在项目这个文件夹中的。

重新再次验证

pod spec lint


这次可以啦

第三步 注册 trunk 并上传

1. pod trunk register 邮箱 '用户名'

输入后进入邮箱中点击链接进行验证

验证完就可以回到终端继续下一步

2. pod trunk me

不出意外已经可以了

我们可以上传了

3.pod trunk push

耐心等待后终于上传成功了

还没结束。pod search 搜索不出来,需要更新,先删除缓存文件。

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

在搜索

pod search OCITButton

漫长的等待后

终于出来了。

Pod::Spec.new do |s|

s.name = "OCITButton"

s.version = "0.0.1"

s.summary = "为了偷懒"

s.description = "让按钮中的图片与标题更舒适放置"

s.homepage = "https://github.com/19940524/OCITButton"

s.license = { :type => 'MIT', :file => 'LICENSE' }

s.author = { "19940524" => "@qq.com" }

s.ios.deployment_target = '7.0'

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

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

s.requires_arc = true

s.framework = "UIKit"

end Pod::Spec.new do |s|

s.name = "OCITButton"

s.version = "0.0.1"

s.summary = "为了偷懒"

s.description = "让按钮中的图片与标题更舒适放置"

s.homepage = "https://github.com/19940524/OCITButton"

s.license = { :type => 'MIT', :file => 'LICENSE' }

s.author = { "19940524" => "@qq.com" }

s.ios.deployment_target = '7.0'

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

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

s.requires_arc = true

s.framework = "UIKit"

end

相关文章

网友评论

      本文标题:上传自己的公开库至cocoapods

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