创建自己的Cocoapod

549 阅读2分钟

Cocoapod 是iOS开发的一个第三方管理的一个工具,但是里面的第三方是怎么传上去的呢,我们能不能自己写个自己比较满意的第三方库,然后传上去分享呢,答案当然是可以的。

  git config --global user.name [username]

  git config --global user.email [email]

Cocoapod 的安装

  • 网上已经有很多的开发者写了文档了这里就不多说了
  • 这个是我电脑重装后重装Cocoapod的参考文档 www.jianshu.com/p/00107eb54…

Github建立一个仓库

  • 登录github建立一个仓库
  • 记录下仓库地址

开始操作提交代码到git

  • cd 进入目录
  • git init
  • git add . //提交工程到缓存区
  • git commit -m 'xxx' //提交代码到本地仓库
  • git remoter add origin xxxxxxx //关联本地仓库到远程仓库
  • git remote //关联连接
  • git push origin master //提交代码到远程仓库
  • 创建成功

创建podspec 描述文件

  • 随便找个别人的库看下这个东西都要写什么我们基本也是要填写这些信息的
  • cd 工程文件夹路径
  • pod spec create XXX //创建了一个 xxx.podspec 文件
  • 打开编辑
  • 因为我现在只是做的很简单的一个测试的所以有些信息就不填了
Pod::Spec.new do |spec|
  spec.name         = "testLib"
  spec.version      = "0.0.1"
  spec.summary      = "testLib"
  spec.description  = "testLib 的详细描述,一定要注意字数比summary长"
    spec.homepage     = "https://github.com/Wlfade/GitTest"
  spec.license      = "MIT"
  spec.author             = { "Wlfade" => "XXXXX@qq.com" }
  spec.source       = { :git => "https://github.com/Wlfade/GitTest.git", :tag => "#{spec.version}" }
  spec.source_files  = "Classes", "Class/*.{h,m}"
end
  • 注意需要打个标签 填写spec.version 的内容 一定要和上面的version 保持一致
  • git tag '0.0.1'
  • git push --tags

注册trunk

  • pod trunk register XXXXX@qq.com 'Wlfade' --verbose
  • 打开邮箱进行验证 点击链接就可以了
  • 回到终端 pod trunk push XXXLib.podspec
  • 更新 文件/Users/XXX/.cocoapods/repos/trunk/Specs

查看结果

  • 这个DCEmoji 是我以前写的 上传练习的基本上流程是一样的
  • podsepec 描述文件
Pod::Spec.new do |s|
s.name = 'DCEmoji'
s.version = '1.0.5'
s.license = 'MIT'
s.summary = 'A emoji putView on iOS.'
s.homepage = 'https://github.com/Wlfade/DCEmoji'
s.authors = {'Wlfade' => 'XXXXX@qq.com'}
s.source = {:git => 'https://github.com/Wlfade/DCEmoji.git', :tag => s.version.to_s }
s.requires_arc = true
s.ios.deployment_target = '8.0'
s.source_files = 'Emoticon/**/*.{h,m,bundle}'
s.resources = 'Emoticon/Model/Emoticons.bundle'
s.framework = 'UIKit'
end
  • 这次练习的这个一直在超时可能网络不行,也可能我这个练习的代码有问题。
  • 总之最后成功后会显示
  • 也可以 pod search XXX 看下是否完成了 找到了就成功了

后续

  • 之后写了什么好的功能的东西也会再次练习上传的,成功了就会更新一下这个文章