上传代码到cocoaPods,通过pod search 能搜索并下载
- 生成SSH Key,然后添加到GitHub上面
$ ssh-keygen -t rsa -C “your email”
在GitHub上面新建一个repository(仓库),加上README和MIT LICENSE,
克隆到本地,下面是克隆成功的输出
$ git clone https://github.com/maybenai/LSCocoaPodsTest.git
Cloning into 'LSCocoaPodsTest'...
remote: Counting objects: 31, done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 31 (delta 3), reused 26 (delta 2), pack-reused 0
Unpacking objects: 100% (31/31), done.
- 将要上传的工程放到克隆的仓库中 这是层级结构
- 推送到远程仓库
$git add .
$git commit -m "cocoaPodsTest"
$ git push -u origin master
Branch master set up to track remote branch master from origin.
Everything up-to-date
- 添加标签
1.先给本地添加标签
$ git tag 0.0.1
$ git tag
0.0.1
2.推送标签到远程
$ git push origin 0.0.1
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/maybenai/CocoaPodsTest.git
* [new tag] 0.0.1 -> 0.0.1
- 添加并填写podspec文件
$ pod spec create CocoaPodsTest
Specification created at CocoaPodsTest.podspec
- 修改podspec文件
Pod::Spec.new do |s|
s.name = "LSCocoaPodsTest"
s.version = "0.0.2"
s.summary = "a cocoaPodsTest named LSCocoaPodsTest."
s.homepage = "https://github.com/maybenai/LSCocoaPodsTest"
s.license= { :type => "MIT", :file => "LICENSE" }
s.author = { "maybenai" => "1014720511@qq.com" }
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/maybenai/LSCocoaPodsTest.git", :tag => "0.0.2" }
s.source_files = "LSCocoaPodsTest/LSCocoaPodsTest/*"
s.requires_arc = true
end
其中,特别注意s.source_files这个字段的后面部分,层级目录一定是podspec所在的文件位置的工程名开始到你要上传的文件目录为止
“” 表示匹配所有文件
“.{h,m}” 表示匹配所有以.h和.m结尾的文件
“**” 表示匹配所有子目录
- 保存podspec文件,然后验证,如果通过会有如下信息,如果没有通过,查看之前的步骤是否有错误。需要注意的点
1.远程仓库是否有tag值,tag值是否和本地的tag值相等
2.podspec信息是否填写正确
3.本地库的东西是否推送到远程仓库
$ pod lib lint
-> CocoaPodsTest (0.0.1)
CocoaPodsTest passed validation.
然后我们再提交到CocoaPods/Specs代码库中,让其他人也可以通过pod install 安装我们的开源库
- 注册trunk,如果有如下信息就可以去邮箱里面去验证
$ pod trunk register 1014720511@qq.com 'cocoapods test' --description='cocoapods test'
[!] Please verify the session by clicking the link in the verification email that has been sent to 1014720511@qq.com
- 上传
pod trunk push
$ pod trunk push
[!] Found podspec `LSCocoaPodsTest.podspec`
Updating spec repo `master`
CocoaPods 1.2.1 is available.
To update use: `sudo gem install cocoapods`
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.2.1
Validating podspec
-> LSCocoaPodsTest (0.0.2)
如果出现
[!] Unable to accept duplicate entry for:
说明已经提交到cocoapods仓库中去了,然后有可能就是本地的仓库没有更新,利用
pod repo update
更新本地仓库
这个时候,就pod search 一下你的工程。如果没有,就把~/Library/Caches/CocoaPods这里面的search_index.json文件删了再重新搜
$ pod search LSCocoapodstest
Creating search index for spec repo 'master'.. Done!