如何制作自己的Pod库

  • GitHub新建自己的git repository


    NewRepository
    NewRepository
  • 将项目clone到本地
    git clone git@github.com:ZHANGMRXIN/ZXCategory.git

    CloneReposiorty
    CloneReposiorty

  • 初始化好项目,将Pod库文件建立好目录


    PodFileDirectory
    PodFileDirectory
  • 给仓库创建个podspec文件
    pod spec create ZXCategory git@github.com:ZHANGMRXIN/ZXCategory.git

    CreatePodSpec
    CreatePodSpec

  • 编写ZXCategory.podspec文件

项目中不做子目录分层显示

Pod::Spec.new do |s|
  s.name             = "ZXCategory"
  s.version          = "0.0.6"
  s.summary          = "Custom Category used on iOS."
  s.description      = <<-DESC
                       Custom Category used on iOS, which implement by Objective-C.
                       DESC
  s.homepage         = "https://github.com/ZHANGMRXIN/ZXCategory"
  s.license          = 'MIT'
  s.author           = { "xinzhang" => "zx270611346@gmail.com" }
  s.platform         = :ios, '7.0'
  s.source           = { :git => "https://github.com/ZHANGMRXIN/ZXCategory.git", :tag => s.version }
  s.source_files     = 'ZXCategory/**/*'
  s.requires_arc     = true
end

项目中做子目录分层显示

Pod::Spec.new do |s|
  s.name             = "ZXCategory"
  s.version          = "0.0.6"
  s.summary          = "Custom Category used on iOS."
  s.description      = <<-DESC
                       Custom Category used on iOS, which implement by Objective-C.
                       DESC
  s.homepage         = "https://github.com/ZHANGMRXIN/ZXCategory"
  s.license          = 'MIT'
  s.author           = { "xinzhang" => "zx270611346@gmail.com" }
  s.platform         = :ios, '7.0'
  s.source           = { :git => "https://github.com/ZHANGMRXIN/ZXCategory.git", :tag => s.version }
  s.requires_arc     = true

# UIView 和 EasyLog 在工程中以子目录显示
  s.subspec 'UIView' do |ss|
    ss.source_files = 'ZXCategory/UIView/*.{h,m}'
  end

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

end

*** s.source_files = ' '*** 的多种写法

ss.source_files = 'ZXCategory/UIView/*.{h,m}'

表示ZXCategory/UIView/目录下的所有 .h.m 文件

s.source_files = 'ZXCategory/**/ .'
/后面的 . 应是 星号,MarkDowm语法冲突在此不能正常显示

表示ZXCategory/ 目录下所有文件,包括子目录下所有文件。 **/.表示递归

当有多个文件时,应用,隔开

 s.source_files = 'MMDrawerController/MMDrawerController.{h,m}', 'MMDrawerController/UIViewController+MMDrawerController*'

  • 把当前版本上传到GitHub,并打上tag(版本号) 即tag => s.version 并确保tag push到GitHub
    git push origin --tags

    PushTags
    PushTags

  • 检查ZXCategory.podspec文件是否编写争取
    pod lib lint

    CheckPodSpec
    CheckPodSpec

  • 将ZXCategory.podspec文件上传给CocoaPods
    pod Trunk 注册
    pod trunk register zx270611346@gmail.com 'ZXCategory'

    检查成功与否
    登录邮箱,点击确认
    终端输入 pod trunk me

    PodTrunk
    PodTrunk

  • 上传ZXCategory.podspec 到 CocoaPods/repo
    pod trunk push ZXCategory.podspec

    PodspecPushSuccess
    PodspecPushSuccess

shit! 报错,貌似上传的版本不能小于之前的版本,CocoaPods 为了使用的人着想,要求向下作兼容。

DuplicateError
DuplicateError

  • 检测是否上传成功
    pod search ZXCategory

    PushSearchCheck
    PushSearchCheck

  • Done
    执行 pod install or pod install --no-repo-update命令

    UsePod
    UsePod

  • 另附获取提交到GitHub上的图片资源的两种链接

https://raw.githubusercontent.com/ZHANGMRXIN/ZXCategory/master/Resources/NewProject.png
https://github.com/ZHANGMRXIN/ZXCategory/raw/master/Resources/NewProject.png

参考:
CocoaPods
DWCategory
MMDrawerController

推荐阅读更多精彩内容