制作自己的cocoapods

2018-07-18  本文已影响68人  CCloud

项目中用到了共同的一些东西,之前都是拖来拖去.
终于有时间,学习记录一下制作一个cocoapods库

参考了以下文章
夏天然后 的 [干货最新]将自己库添加Cocoapods支持
草原烈鹰 的 iOS 自制cocoapod里的第三方


第一步
在GitHub 上创建一个项目
第二步
终端进入你的项目, 执行命令  
 pod spec create 库名
会生成一个文件    库名.podspec
第三步
用xcode编辑刚刚生成的文件    库名,podspec

文件中:
Pod::Spec.new do |s|
# 名称 使用的时候pod search [name]
s.name = “ ”
# 代码库的版本
s.version = “0.0.1”
# 简介
s.summary = “最好自己改下.”
# 主页
s.homepage = "”
# 许可证书类型,要和仓库的LICENSE 的类型一致
s.license = “MIT”
# 作者名称 和 邮箱
s.author = { “" }
# 作者主页
s.social_media_url = "”
# 代码库最低支持的版本
s.platform = :ios, “8.0”
# 代码的Clone 地址 和 tag 版本
s.source = { :git => "", :tag => “0.0.1” }
# 如果使用pod 需要导入哪些资源
s.source_files = "class/**/*.{swift}”
s.resources = “class.bundle”
# 框架是否使用的ARC
s.requires_arc = true

我参考了MJRefresh的内容

Pod::Spec.new do |s|
  s.name         = 'MJRefresh'
  s.version      = '3.1.15.4'
  s.summary      = 'An easy way to use pull-to-refresh'
  s.homepage     = 'https://github.com/CoderMJLee/MJRefresh'
  s.license      = 'MIT'
  s.authors      = {'MJ Lee' => 'richermj123go@vip.qq.com'}
  s.platform     = :ios, '6.0'
  s.source       = {:git => 'https://github.com/CoderMJLee/MJRefresh.git', :tag => s.version}
  s.source_files = 'MJRefresh/**/*.{h,m}'
  s.resource     = 'MJRefresh/MJRefresh.bundle'
  s.requires_arc = true   
end
第四步
验证 库名.podspec 文件,终端  pod lib lint 库名.podspec
如果有错误,根据提示改就可以
第五步
将编辑好的文件,和库文件推到GitHub,并设置tag
第六步
推到cocoapods
pod trunk push 库名.podspec

如果报以下错误,是因为没有注册

 [!] You need to register a session first.

注册下,然后在邮箱里验证链接

pod trunk register 电子邮箱 '您的姓名' --description='macbook pro’

推送成功后

 🎉  Congrats

 🚀  class (0.0.1) successfully published
 📅  July 18th, 02:10
 🌎  https://cocoapods.org/pods/class
 👍  Tell your friends!
上一篇 下一篇

猜你喜欢

热点阅读