制作自己的 cocoapods 库

2020-06-13  本文已影响0人  叫我小黑

制作步骤

1. 创建远程仓库
2. 将仓库克隆到本地
git clone https://github.com/a-stupid-wood/WKBCategory.git
3. 创建.podspes文件
pod spec create WKBCategory
4. 本地目录中创建共享的类
5. 编辑podspec文件
Pod::Spec.new do |s|
  s.name         = "WKBCategory"
  s.version      = "0.1.2"
  s.summary      = "WKBCategory"
  s.description  = "封装自己项目常用到的类别"
  s.homepage     = "https://github.com/a-stupid-wood/WKBCategory"
  s.license      = "MIT"
  s.author       = { "Kerwin" => "13763072736@163.com" }
  s.source       = { :git => "https://github.com/a-stupid-wood/WKBCategory.git", :tag => "#{s.version}" }
  s.requires_arc = true
  s.platform     = :ios, "9.0"
  s.source_files = "WKBCategory/WKBCategory.h"
  s.frameworks = 'Foundation', 'UIKit'

  s.subspec 'UIView+wkb' do |ss|
    ss.source_files = "WKBCategory/UIView+wkb/*.{h,m}"
  end
  
  s.subspec 'NSString+wkb' do |ss|
    ss.source_files = "WKBCategory/NSString+wkb/*.{h,m}"
  end

  s.subspec 'UIButton+wkb' do |ss|
    ss.source_files = "WKBCategory/UIButton+wkb/*.{h,m}"
  end

  s.subspec 'UIColor+wkb' do |ss|
    ss.source_files = "WKBCategory/UIColor+wkb/*.{h,m}"
  end

  s.subspec 'UIImage+wkb' do |ss|
    ss.source_files = "WKBCategory/UIImage+wkb/*.{h,m}"
  end

  s.subspec 'NSDate+wkb' do |ss|
    ss.source_files = "WKBCategory/NSDate+wkb/*.{h,m}"
  end

end
6. 上传到远程仓库并打tag
git add .
git commit -m "提交描述"
git push -u origin master
git tag 0.1.2
git push --tags
7. 验证podspec
pod spec lint

验证成功会出现以下提示:

Analyzed 1 podspec.
WKBCategory.podspec passed validation.
8. pod主干注册
pod trunk register 13763072736@163.com 'flow' --verbose
9. 发布pod库
pod trunk push WKBCategory.podspec --allow-warnings

这个时间比较久,成功完成之后就可以在终端通过 pod search 搜到你的 cocoapods 库


可能会遇到的错误

执行 pod trunk push 命令时,可能会出现下面的错误

[!] Authentication token is invalid or unverified. Either verify it with the email that was sent ...
解决办法是执行下面的命令

pod trunk register 13763072736@163.com 'flow' --verbose

然后在自己邮箱里面去点击,那个邮件里面的连接,就可以了

git 的常用命令

git clone 远端仓库git地址
git init  //初始化一个空的 git 仓库
git remote add origin 远端仓库git地址 //给本地仓库添加远程仓库
git pull origin master //拉取远程仓库 master 分支的代码更新本地仓库代码
git add .  //将所有修改和新添的文件存到缓存区
git commit -m "提交描述" //将缓存区的代码提交到本地仓库
git push -u origin master  //将本地仓库的代码推送到远程仓库
上一篇下一篇

猜你喜欢

热点阅读