cocoapods管理私有库

参考文章
http://www.cocoachina.com/ios/20150228/11206.html
http://blog.csdn.net/yohunl/article/details/48471489

准备工作

1、有自己的git仓库
2、需要管理的私有库

在git服务器上新建一个私有库MyPrivateCocoaRepo

$pod repo add MyPrivateCocoaRepo https://git.oschina.net/huanghehg/MyPrivateCocoaRepo.git
Cloning spec repo `MyPrivateCocoaRepo` from `https://git.oschina.net/huanghehg/MyPrivateCocoaRepo.git`

将自己的私有库克隆到本地,cd到目录下,打上tag

$git clone https://git.oschina.net/huanghehg/MyTool.git
$cd ~/MyTool
$git tag 0.0.6
$git push --tags

在该目录下创建spec文件,vim

$pod spec create MyTool https://git.oschina.net/huanghehg/MyTool.git
$vim MyTool.podspec

删除注释,不删除也可以但是看起来不方便

Pod::Spec.new do |s|
  s.name             = "MyTool"    #名称
  s.version          = "0.1.0"             #版本号
  s.summary          = "Just Testing. MyTool"     #简短介绍,下面是详细介绍
  s.description      = <<-DESC
                       Testing Private Podspec.
                       *it is just a test file
                       DESC
  s.homepage         = "https://git.oschina.net/huanghehg/MyTool.git"                        #主页,这里要填写可以访问到的地址,不然验证不通过
  s.license          = 'MIT'              #开源协议
  s.author           = { "huanghehg" => "[email protected]" }            #作者信息
  s.source           = { :git => "https://git.oschina.net/huanghehg/MyTool.git", :tag => "0.1.0" }      #项目地址,这里不支持ssh的地址,验证不通过,只支持HTTP和HTTPS,最好使用HTTPS
  s.platform     = :ios, '7.0'            #支持的平台及版本
  s.requires_arc = true                   #是否使用ARC,如果指定具体文件,则具体的问题使用ARC

  s.source_files = 'Pod/Classes/**/*'     #代码源文件地址,**/*表示Classes目录及其子目录下所有文件,如果有多个目录下则用逗号分开,如果需要在项目中分组显示,这里也要做相应的设置
  s.resource_bundles = {
    'PodTestLibrary' => ['Pod/Assets/*.png']
  }                                       #资源文件地址

  s.public_header_files = 'Pod/Classes/**/*.h'   #公开头文件地址
  s.frameworks = 'UIKit'                  #所需的framework,多个用逗号隔开
  s.dependency 'AFNetworking', '~> 2.3'   #依赖关系,该项目所依赖的其他库,如果有多个需要填写多个s.dependency
end</twitter_username>

配置完成保存

pod lib lint (验证,不能出现error 如果出现warn 可以在后面跟上--allow-warnings,但不能确保你的类正确)
MyTool passed validation.

然后就可以将spec提交到刚开始的repo里了

pod repo push MyPrivateCocoaRepo MyTool.podspec (--allow-warnings)

此时pod search MyTool
cocoapods管理私有库_第1张图片
就可以在Podfile中使用了

以上是添加到私有库的方法,在项目中使用时需要在Podfile中添加刚刚新建的私有repo地址

source 'https://git.oschina.net/huanghehg/MyPrivateCocoaRepo.git' 
source 'https://github.com/CocoaPods/Specs.git'

添加到public的方法后期会在总结

你可能感兴趣的:(CocoaPods)