CocoaPods|CocoaPods 私有仓库的创建教程

CocoaPods 私有仓库的创建教程

创建私有pod首先需要一个容器,类似于 The CocoaPods Master Repo,就可以使s用
pod 'AFNetworking'

来添加我们的私有库了。
如何建立一个私有 Repo
首先看下命令行中 pod 有哪些 COMMAND
Commands: ... + repoManage spec-repositories ...

再看下 repo 包含哪些命令
+ addAdd a spec repo + lintValidates all specs in a repo > listList repos + pushPush new specifications to a spec-repo + removeRemove a spec repo + updateUpdate a spec repo

继续看下 add 下面包含哪些方法
$ pod repo add NAME URL [BRANCH]

就此,我们得到了一个创建私有 repo 的一个方法(URL 为 git 上的一个仓库,已初始化完成)
pod repo add DDRepo https://github.com/dingdingtion/Specs

添加完成后可以看下 repo 的列表
pod repo list

DDRepo - Type: git (master) - URL:https://github.com/dingdingtion/Specs.git - Path: /Users/dingding/.cocoapods/repos/DDRepo

到此我们已经有了一个自己的容器
pod私有库的创建 查看 pod 相关命令
+ lib Develop pods

查看 lib 的命令
+ createCreates a new Pod + lintValidates a Pod

查看 create 的命令
$ pod lib create NAME

现在就要使用 create 来建立一个自己的库
执行命令
pod lib create DDTest

会出现以下几个问题(如果没有出现相关问题,可以考虑升级pod来解决)
  1. What language do you want to use?? [ Swift / ObjC ]
  2. Would you like to include a demo application with your library? [ Yes / No ]
  3. Which testing frameworks will you use? [ Specta / Kiwi / None ]
  4. Possible answers are [ Specta / Kiwi / None ]
  5. Would you like to do view based testing? [ Yes / No ]
  6. What is your class prefix?
在当前目录生成了一个文件夹 DDTest
主要看下 DDTest.podspec 文件
1 # 2 # Be sure to run `pod lib lint DDTest.podspec' to ensure this is a 3 # valid spec before submitting. 4 # 5 # Any lines starting with a # are optional, but their use is encouraged 6 # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 7 # 8 9 Pod::Spec.new do |s| 10s.name= 'DDTest' 11s.version= '0.0.1'/// 此处版本号需要注意,发布前需要修改 12s.summary= 'A short description of DDTest.' 13 14 # This description is used to generate tags and improve search results. 15 #* Think: What does it do? Why did you write it? What is the focus? 16 #* Try to keep it short, snappy and to the point. 17 #* Write the description between the DESC delimiters below. 18 #* Finally, don't worry about the indent, CocoaPods strips it! 19 20s.description= <<-DESC 21 TODO: Add long description of the pod here. 22DESC 22DESC 23 24s.homepage= 'https://github.com/******@qq.com/DDTest' 25# s.screenshots= 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' 26s.license= { :type => 'MIT', :file => 'LICENSE' } 27s.author= { '******@qq.com' => '132******@wo.com.cn' } 28s.source= { :git => 'https://github.com/******@qq.com/DDTest.git', :tag => s.version.to_s } 29# s.social_media_url = 'https://twitter.com/' 30 31s.ios.deployment_target = '8.0' 32 33s.source_files = 'DDTest/Classes/**/*' 34 35# s.resource_bundles = { 36#'DDTest' => ['DDTest/Assets/*.png'] 37# } 38 39# s.public_header_files = 'Pod/Classes/**/*.h' 40# s.frameworks = 'UIKit', 'MapKit'/// 系统依赖库 41# s.dependency 'AFNetworking', '~> 2.3' /// 外部依赖库 42 end

此处需要注意下,我们所有文件存放的位置
33s.source_files = 'DDTest/Classes/**/*'

source 地址必须为当前git的地址
28s.source= { :git => 'https://github.com/******@qq.com/DDTest.git', :tag => s.version.to_s }

发布私有库之前需要校验 lib 的合法性
pod lib lint --silentShow nothing --verboseShow more debugging information --no-ansiShow output without ANSI codes --helpShow help banner of specified command

看下校验结果,警告暂时忽略
?DDTest git:(master) pod lib lint -> DDTest -> DDTest (0.1.0) - WARN| summary: The summary is not meaningful. - WARN| url: The URL (https://github.com/***@qq.com/DDTest) is not reachable.

验证完毕后,将私有pod库上传至git中,并添加标签(tag),.git', :tag => s.version.to_s 使得git能找到相对应的版本(注:必须全部提交后,才能进行发布)
git tag '0.0.1'/// s.version必须一致 git push --tags

repo 中添加私有库
看下repo 的相关命令
pod repo --help

Usage:$ pod repo [COMMAND]Manage spec-repositoriesCommands:+ addAdd a spec repo + lintValidates all specs in a repo > listList repos + pushPush new specifications to a spec-repo + removeRemove a spec repo + updateUpdate a spec repo

可以看出使用push来发布
$ pod repo push REPO [NAME.podspec]

pod repo push DDRepo DDTest.podspec--allow-warnings--allow-warningsAllows pushing even if there are warnings --verboseShow more debugging information

可能出现的问题:
  1. s.version 与 git tag 的一致
  2. s.source 地址不一致
  3. 没有错误信息 命令行后添加 --verbose
  4. 有警告不能发布 命令行后面添加 --allow-warnings
【CocoaPods|CocoaPods 私有仓库的创建教程】发布成功后,验证下
pod search 'DDTest'

-> DDTest (0.0.1) A short description of DDTest. pod 'DDTest', '~> 0.0.1' - Homepage: https://github.com/***@qq.com/DDTest - Source:https://github.com/dingdingtion/DDTest.git - Versions: 0.0.1 [DDRepo repo]

在项目中使用私有库
项目中使用需要添加一个source,来指定索引位置
source 'https://github.com/CocoaPods/Specs.git' source 'https://github.com/dingdingtion/Specs.git'pod 'DDTest', '~> 0.0.1'

好了,不出意外的就可以使用了~

    推荐阅读