iOS开发 - 搭建CocoaPods远程私有库(码云平台)

1. 创建本地工程   

      路径:/Users/XXX/Documents/OC-PrivatePods

2. 在码云(https://gitee.com)上创建一个自己的远程私有索引库,用来存放私有框架的详细描述信息.podspec文件 

        iOS开发 - 搭建CocoaPods远程私有库(码云平台)

3. 创建本地的私有索引库文件夹,并与远程私有索引库进行关联

       3.1 查看本地已存在的索引库

            $ pod repo

             iOS开发 - 搭建CocoaPods远程私有库(码云平台)            

     3.2 添加本地私有索引库并与远程私有库

           $ pod repo add WTYProjectSpec https://gitee.com/wty2009/WTYProjectSpec.git

     3.3 再次查看本地已存在的索引库

           iOS开发 - 搭建CocoaPods远程私有库(码云平台)

4. 在代码托管平台码云(https://gitee.com)创建一个用来存放项目基础组件的仓库WTYLogDebugKit 

         iOS开发 - 搭建CocoaPods远程私有库(码云平台)

 5. 快速创建模板测试工程 

       5.1 快速创建模板测试工程 在指定路径下

             $ cd /Users/XXX/Documents/OC-PrivatePods

             $ pod lib create WTYLogDebugKit 

              iOS开发 - 搭建CocoaPods远程私有库(码云平台)

      5.2 填写以上信息后Xcode会自动打开测试工程,在测试模板工程文件夹下,我们可以看到如下:     

            iOS开发 - 搭建CocoaPods远程私有库(码云平台)       

      5.3 删除Replace.m文件,新建WTYLogDebugKit(.h .m)文件,再回到Example路径下,重新执行pod install操作

           iOS开发 - 搭建CocoaPods远程私有库(码云平台)

           $ cd /Users/XXX/Documents/OC-PrivatePods/WTYLogDebugKit/Example 

           $ pod install

           我们可以在模板测试工程中进行修改和操作!

6. 将上面的模板测试工程,提交到第4步创建的远程代码仓库

       $ cd /Users/XXX/Documents/OC-PrivatePods/WTYLogDebugKit

       $ git status

       $ git add .

       $ git commit -m'基础组件测试工程'

        编辑WTYLogDebugKit 模版工程的WTYLogDebugKit.podspec文件

        iOS开发 - 搭建CocoaPods远程私有库(码云平台)

       $ pod lib lint (验证上一步编辑的 WTYLogDebugKit.podspec文件)

       如果有ERROR,则需要去一个个修改完成,例如某个文件没有正确的引入依赖库等都会造成ERROR,解决好所  

       有的ERROR后,验证结果如下:

       iOS开发 - 搭建CocoaPods远程私有库(码云平台)

       这是一个警告,目前也并没有找到合适的解决办法,我们添加 --allow-warnings进行忽略

      $ pod lib lint --allow-warnings

      WTYLogDebugKit passed validation.

      表明验证通过

      $ git status

      $ git add .

      $ git commit -m '编辑spec文件'

      $ git remote add origin https://gitee.com/wty2009/WTYLogDebugKit.git (将本地库与远程代码仓库进行关联)

      $ git push origin master  (提交到远程仓库)

       如里有报错误:

      iOS开发 - 搭建CocoaPods远程私有库(码云平台)

      可以输入:git push -f  或 git pull origin master --allow-unrelated-histories  //把远程仓库和本地同步,消除差异

     $ git tag '0.1.0' (要与WTYLogDebugKit.podspec文件中的tag值保持一致)

     $ git push --tags(将tag提交到远程)

     $ pod spec lint --allow-warnings(验证远程是否正确,注意:Username与Password一定要填写正确)

      WTYLogDebugKit.podspec passed validation.    

      表明验证通过

7. 将podspec文件提交到本地的私有索引库

      $ pod repo

       iOS开发 - 搭建CocoaPods远程私有库(码云平台)

      $ pod repo push WTYProjectSpec WTYLogDebugKit.podspec

      注意:提交后,依然会验证 podspec文件,验证通过后 会自动上传到在远程spec索引库,不信的话你可以看看在第二步创建的

      Spec远程私有索引库,是不是多了一个 WTYLogDebugKit/0.1.0文件!

8. 添加及修改基础组件内容

       $ cd /Users/XXX/Documents/OC-PrivatePods/WTYLogDebugKit

       编辑WTYLogDebugKit 模版工程的WTYLogDebugKit.podspec文件 

       iOS开发 - 搭建CocoaPods远程私有库(码云平台)

      $ git status

      $ git add .

      $ git commit -m'新增Base,Tool文件内容'

      $ git push origin master (提交到远程)

      $ git tag '0.1.1'

      $ git push --tags

      $ pod repo push WTYLogDebugKit WTYLogDebugKit.podspec

9. 在基础组件WTYLogDebugKit内部生成子库

      问题描述:当我们执行完第8步后,我们发现主工程的Pods中并没有按文件夹(Log,Performance)进行不同类的划分,同

      时当我们仅仅想引入一个Log库时,连同Performance也引入进项目中,冗余代码量增加!

      修改WTYLogDebugKit.podspec文件 
      iOS开发 - 搭建CocoaPods远程私有库(码云平台)        

      $ cd /Users/XXX/Documents/OC-PrivatePods/WTYLogDebugKit

      $ git status

      $ git add .

      $ git commit -m'生成子库文件夹'

      $ git push origin master (提交到远程)

      $ git tag '0.1.3'

      $ git push --tags

      $ pod repo push WTYLogDebugKit WTYLogDebugKit.podspec

      $ pod search WTYLogDebugKit

       iOS开发 - 搭建CocoaPods远程私有库(码云平台)

      至此生成子库

10. 主工程利用Pods使用生成的私有框架

         用Xcode打开主工程编辑Podfile文件 

         iOS开发 - 搭建CocoaPods远程私有库(码云平台)

        $ pod install

        打开WTYLogDebugKit.xcworkspace,此时在pod中可以找到远程私有库的代码