两个概念:

1.code repository是代码仓库,我们把包代码上传到这个仓库。

2.spec repository是配置仓库,所有的配置按照包名、版本号分门别类的存放在这个仓库。这个仓库只用来存放spec文件,不存放代码。

步骤

第一步:制作cocopods的依赖库,也就是code repository。

创建一个私有的project

把仓库clone到本地  git clone xxxx(仓库地址)

//打开隐藏文件的命令:
defaults write com.apple.finder AppleShowAllFiles -bool true//关闭隐藏文件的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false

把代码XQPhotoBrowse拖到此处,并写一个demo

创建.podspec、LICENSE、README.md3 个文件

每个 Pods 依赖库必须有且仅有一个名称和依赖库名保持一致,后缀名为 .podspec 的描述文件,如PhotoLibraryTT.podspec

.podspec创建有2种方法

1.直接copy一份,并修改里面的内容

2.执行pod spec create PhotoLibraryTT,创建一个新的Pod::Spec.new do |s|

s.name        = "PhotoLibraryTT"
s.version      = "1.0.3"
s.summary      = "A short description of PhotoLibrary."
s.homepage    = "https://xxxxx"
s.license      = "MIT"
s.author            = { "xx" => "x'x@qq.com" }
s.platform    = :ios, "8.0"
s.source      = { :git => "https://xxxx.git", :tag => "#{s.version}" }
s.source_files  = "PhotoLibrary/XQPhotoBrowse", "XQPhotoBrowse/**/*.{h,m}"
s.dependency 'SDWebImage'
end

验证podspec的有效性。

pod lib lint

如果有警告,会导致无法通过,需要添加--allow-warnings

如果使用了c函数相关的,需要添加--use-libraries

如果依赖了私有库,需要添加库的源--sources='https://xxxx'

pod lib lint --allow-warnings pod lib lint --sources='https://xxxx' --use-libraries --allow-warnings

验证通过后,把代码提交到仓库即可

git add -A && git commit -m "add pod files"

git push origin master

git tag -a v1.0.3 -m “1.0.3版本”  //一定要打tag

第二步 创建并设置一个私有的Spec Repository

在gitlab上创建一个空的仓库,命名为Specs,这个仓库是用来存放我们自己所有的私有库的spec文件,就如同官方的https://github.com/CocoaPods/Specs是用来存放所有官方的specs文件一样。

在终端执行命令:pod repo add Specs http://xxx.git注意:上面的命令的解释如下:

pod repo add REPO_NAME SOURCE_URL

其中的 REPO_NAME 是我们要添加的私有repo的名称(这里我们待会填的是:Specs),后面是仓库的 gitlab 地址。这里做的其实是创建的工作,也就是在~/.cocoapods/repo目录下添加了一个以你的私有repo为名的文件夹,但是并没有添加spec文件。

至此,我们已经在本地得到我们自己的私有仓库 Specs ,这是一个空的仓库。

添加 刚才第四步创建的 PhotoLibraryTT.podspec 到你的 Spec Repository。pod repo push Specs PhotoLibraryTT.podspec

如果有警告,会导致无法通过,需要添加--allow-warnings

如果使用了c函数相关的,需要添加--use-librariespod repo push Specs PhotoLibraryTT.podspec --use-libraries --allow-warnings

pod search PhotoLibraryTT

在个人项目中的Podfile中增加刚刚制作的好的Pod并使用。source 'https://xxxxxxx.git'  //私有库地址

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
inhibit_all_warnings!
def default_pods
pod "PhotoLibraryTT"
end
target ‘Demo’ do
default_pods
end