发布自己的cocoapods开源库按照以下步骤,良心制作,包教包会!!
下面我会通过一个名为IFMMenu的项目来讲解一下整个过程。
github上创建项目仓库的时候记得创建LICENSE(许可证/授权)文件,此文件必须要有。

tag因为cocoapods是依赖tag版本的,所以必须打tag,以后再次更新只需要把你的项目打一个tag,然后修改.podspec文件中的版本接着提交到cocoapods官方就可以了,提交命令请看下面
|
1
2
3
4
5
|
//为git打tag, 第一次需要在前面加一个v
git tag “v1.0.0”
git push —tags
|
trunk需要CocoaPods 0.33版本以上,用pod --version命令查看版本,如果版本低,需要升级。
|
1
2
3
4
5
6
|
pod —version
//版本低于0.33
sudo gen install cocoapods
pod setup
|
已经注册过的不需要注册,怎么看自己有没有注册
|
1
2
|
pod trunk me
|

若未注册,执行以下命令,邮箱以及用户名请对号入座。用户名我使用的是Github上的用户名。
|
1
2
3
|
// 加上–verbose可以输出详细错误信息,方便出错时查看。
pod trunk register example@example.com ‘liugangios’ —verbose
|
注册完成之后会给你的邮箱发个邮件,进入邮箱邮件里面有个链接,需要点击确认一下。
注册完成后使用pod trunk me检验注册是否成功。
cd到你项目的目录,执行命令
|
1
2
|
pod spec create IFMMenu
|
创建好后,打开.podspec,删除注释, 前面有#的为注释,也可以用以下代码替换,然后编辑自己的库信息。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
Pod::Spec.new do |s|
s.name = ‘IFMMenu’
s.version = ‘1.0.2’
s.authors = { ‘liugangios’ => ‘example@example.com’ }
s.homepage = ‘https://github.com/liugangios/IFMMenu’
s.summary = ‘a dropdown menu for ios like wechat homepage.’
s.source = { :git => ‘https://github.com/liugangios/IFMMenu.git’,
:tag => s.version.to_s }
s.license = { :type => “MIT”, :file => “LICENSE” }
s.platform = :ios, ‘7.0’
s.requires_arc = true
s.source_files = ‘IFMMenu’
s.public_header_files = ‘IFMMenu/*.h’
s.ios.deployment_target = ‘7.0’
end
|
s.name:名称,pod search搜索的关键词,注意这里一定要和.podspec的名称一样,否则报错s.version:版本号,to_s:返回一个字符串s.author:作者s.homepage:项目主页地址s.summary: 项目简介s.source:项目源码所在地址s.license:许可证s.platform:项目支持平台s.requires_arc: 是否支持ARCs.source_files:需要包含的源文件s.public_header_files:需要包含的头文件s.ios.deployment_target:支持的pod最低版本其他一些非必要字段
s.social_media_url:社交网址s.resources:资源文件s.dependency:依赖库,不能依赖未发布的库s.license= { :type => “MIT”, :file => “LICENSE” }
这里建议这样写,如果写别的会报警告,导致后面一直提交失败。
source_files写法及含义
|
1
2
3
4
|
“IFMMenu/*
“IFMMenu/IFMMenu/*.{h,m}”
“IFMMenu/**/*.h“
|
*表示匹配所有文件
*.{h,m}表示匹配所有以.h和.m结尾的文件
**表示匹配所有子目录
s.source常见写法
|
1
2
3
4
|
s.source = { :git => “https://github.com/liugangios/IFMMenu.git”, :commit => “68defea” }
s.source = { :git => “https://github.com/liugangios/IFMMenu.git”, :tag => 1.0.0 }
s.source = { :git => “https://github.com/liugangios/IFMMenu.git”, :tag => s.version }
|
commit => "68defea" 表示将这个Pod版本与Git仓库中某个commit绑定tag => 1.0.0表示将这个Pod版本与Git仓库中某个版本的comit绑定tag => s.version表示将这个Pod版本与Git仓库中相同版本的comit绑定到此检查一下你工程中有以下文件:
.podspec文件,LICENSE文件
使用以下命令测试本地.podspec文件是否存在语法错误。
|
1
2
|
pod spec lint IFMMenu.podspec —verbose
|
|
1
2
|
pod trunk push IFMMenu.podspec
|
时间较长,耐性等待,大概5-10分钟,发布成功后会有以下提示

这个时候使用pod search搜索的话会提示搜索不到,可以执行以下命令更新本地search_index.json文件
|
1
2
|
rm ~/Library/Caches/CocoaPods/search_index.json
|
然后
|
1
2
|
pod search IFMMenu
|
该命令会重新创建search_index.json文件,5-10分钟,耐性等待

|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
git tag “v1.0.0”
git push —tags
pod trunk register example@example.com ‘liugangios’ —verbose
pod trunk me
pod spec create IFMMenu
//编辑 IFMMenu.podspec
pod spec lint IFMMenu.podspec
pod trunk push IFMMenu.podspec
rm ~/Library/Caches/CocoaPods/search_index.json
pod search IFMMenu
|
|
1
2
|
[!] Unable to accept duplicate entry for: XXXXX (1.0.0)
|
意思是:不能接受同一版本的提交
解决方案:
1、执行如下命令
|
1
2
3
|
git tag 1.0.1
git push —tags
|
2、修改XXXX.podspec文件中的内容
|
1
2
3
|
s.version = “1.0.1”
s.source = { :Git => “https://github.com/xxx/xxx.git”, :tag => “1.0.1” }
|
3、执行命令pod spec lint、pod trunk push 库名.podspec验证并提交到CocoPods
IFMMenu是一个仿微信首页添加菜单的多功能、多种属性可自定义的下拉菜单,欢迎download下载提意见,star,感谢阅读。
摘自:http://ios.jobbole.com/93284/
你必须 登录后 才能对文章进行评论!