创建cocoaPods仓库

2018-05-30  本文已影响8人  SpringSunLcy

我们平时会开源一些库到github上,供自己和大家使用,为了使用更方便,大家可以把比较常用的或者比较不错的库支持下pod,下面以一个例子来说一下制作过程。

创建远程项目

在github上创建一个新仓库

image.png

创建完成后:
1.cd到本地的某一个目录,将远程项目clone下来;
2.cd到项目目录下创建工程;

生成.podspec文件

在项目目录下执行下面代码
pod spec create SSLFoundation
这时候本地会生成一个SSLFoundation.podspec文件。
打开.podspec文件,以#开头的是注释,为了观看方便我把注释都删掉了,编辑文件:

Pod::Spec.new do |s|   
  s.name         = "SSLFoundation"
  s.version      = "0.0.1"
  s.summary      = "iOS 基础库"

  s.description  = <<-DESC
                   iOS 基础库,持续更新
                   DESC

  s.homepage     = "https://github.com/GitHubLcy/SSLFoundation.git"

  s.license      = "MIT"

  s.author             = { "SpringSunLcy" => "13391550973@163.com" }

  s.platform     = :ios, "8.0"
  s.ios.deployment_target = "8.0"

  s.source       = { :git => "https://github.com/GitHubLcy/SSLFoundation.git", :tag => "#{s.version}" }

  s.source_files  = "Classes/SSLFoundationHeader.h"

  s.subspec 'UI' do |ss|
    ss.source_files = 'Classes/UI/*.{h,m}'
  end

  s.subspec 'Category' do |ss|
    ss.source_files = 'Classes/Category/*.{h,m}'
  end

  s.frameworks = "Foundation","UIKit"

end

字段说明:

image.png

本地验证

pod lib lint SSLFoundation.podspec --verbose --use-libraries --allow-warnings

验证的时候可能会出现一些问题,不过别慌,错误都会有提示的,像下面这样,这个的错误的原因就是description是空的,按照提示修改就好。

lcy:SSLFoundation lcy$ pod lib lint SSLFoundation.podspec

 -> SSLFoundation (0.0.1)
    - ERROR | description: The description is empty.
    - ERROR | [iOS] unknown: Encountered an unknown error (The `SSLFoundation` pod failed to validate due to 1 error:
    - ERROR | description: The description is empty.

) during validation.

[!] SSLFoundation did not pass validation, due to 2 errors.
You can use the `--no-clean` option to inspect any issue.

验证通过以后有下面这样的提示:

lcy:SSLFoundation lcy$ pod lib lint SSLFoundation.podspec

 -> SSLFoundation (0.0.1)

SSLFoundation passed validation.

提交代码

git add . && git commit -m "version 0.0.1"
 
git tag '1.0.0'    //和上面.podspec一致
 
git push --tags
 
git push origin master

这里的tag一定不要忘记打,不然就会报错。

远程验证

pod spec lint SSLFoundation.podspec --verbose --use-libraries --allow-warnings

push本地的podspec文件到cocoaPods主分支上

pod trunk register *****@xx.com "SpringSunLcy"
pod trunk push SSLFoundation.podspec  --use-libraries --allow-warnings

如果trunk注册过了可以跳过注册直接推。
推送成功提示:

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

 🚀  SSLFoundation (0.0.1) successfully published
 📅  May 30th, 02:03
 🌎  https://cocoapods.org/pods/SSLFoundation
 👍  Tell your friends!
--------------------------------------------------------------------------------

成功后就可以pod下来了,每次修改都要升版本,改一次升一次版本。

常见问题

1. [!] Unable to find a pod with name, author, summary, or description matching 'SSLFoundation '
podspec已经推送到远程,但是使用pod search命令不能搜到上传的库可以使用 rm ~/Library/Caches/CocoaPods/search_index.json删除索引,然后再使用pod search,等一会儿就能出现了。

项目地址:https://github.com/GitHubLcy/SSLFoundation.git
参考文章:
https://www.jianshu.com/p/7672943d8808
https://www.jianshu.com/p/408ac99e5e51

上一篇 下一篇

猜你喜欢

热点阅读