CocoaPods私有repo

CocoaPods 作为iOS常用的包管理工具,给我们开发带来了很多便利之处,我们可以使用别人的作品来帮助我们快速的开发,比如著名的AFNetworkingMasonry等。有时候我们希望将自己团队的Pod集中管理,又和官方的区别开来,这里就需要创建自己团队的Repo

创建公开Pod库

创建公开Pod, 官网上有详细的教程, 这里不再叙述。

添加私有Pod库

在开始之前,需要分清楚两个概念:

准备工作

  1. Repo库
    repo是存放所有Pod库的文件, CocoaPods的库是master,而我们要创建的是一个平行的库,
    这里以我的库为例,创建的是momo13014
  2. Pod库
    自己的pod库,比如AFNetworking

  3. 创建私有repo
    首先明确我们repo存放的地址

1
2
3
4
# 官方库
source 'https://github.com/CocoaPods/Specs.git'
# 私有库
source 'https://github.com/momo13014/Specs.git'

明确以下四个概念(分别给出例子)

repo库地址: https://github.com/momo13014/Specs.git
repo名 : momo1301
pod库地址: https://github.com/momo13014/SDNetworking.git
pod名: SDNetworking

千万不要混淆了!!!

开始创建

  1. 首先我们在存放repo库的server上穿件一个Specs.git库,我这里是Github,也可以是Gitlab等等
    创建完成后的地址:
    https://github.com/momo13014/Specs

  2. 创建repo库

    1
    2
    3
    4
    $ cd /opt/git
    $ mkdir Specs.git
    $ cd Specs.git
    $ git init --bare
  3. 添加本地repo

    1
    $ pod repo add momo13014 https://github.com/momo13014/Specs
  4. 测试repo成功创建

    1
    2
    $ cd ~/.cocoapods/repos/momo13014
    $ pod repo lint .

    如果出现All the specs passed validation.证明创建成功。

  5. 推送自己的pod库到私有repo库里,这里假设你的pod库和podSpec文件已经写完了

    1
    pod repo push momo13014 SDNetworking.podspec

    每次升级后,更改version,打tag后,推送上去也是这个命令

  6. 升级版本
    首先在你的class里面修改完并且测试通过之后,
    首先更改podspec中的版本号
    1
    2
    3
    4
    5
    6
    7
    8
    #推送本地代码
    git add .
    git push origin master
    # 推送本地tag,假设这里的tag为 1.1.2
    git tag 1.1.2
    git push origin --tags
    #推送更改到repo库
    pod repo push momo13014 SDNetworking.podspec
  7. 使用私有Pod
    在你的Podfile文件中加入repo source
    1
    2
    3
    4
    #官方库
    source 'https://github.com/CocoaPods/Specs.git’
    #私有库
    source 'https://github.com/momo13014/Specs.git'