目的:
遠程, 是為了隊員下載
私有, 是為了只有團隊內(nèi)部人員可以下載
創(chuàng)建步驟:
1.要在遠程托管平臺上創(chuàng)建一個遠程私有庫(這里我用碼市作為遠程代碼管理工具,需要添加ssh公鑰(略)).(https://git.coding.net/chongyingnvhai/FMBase.git), 把自己的三方庫上傳到遠程私有庫.
這個是官方提供的公共的索引庫,所以我們的Spec的文件不能放在這里面.

查看本地倉庫,發(fā)現(xiàn)只有一個master,所以添加一個我們自己的spec的索引庫
wuxianlvzhoudeMacBook-Pro:~ Allison$ pod repo
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/wuxianlvzhou/.cocoapods/repos/master
wuxianlvzhoudeMacBook-Pro:~ Allison$ pod repo add FMBase git@git.coding.net:chongyingnvhai/FMSpec.git
Cloning spec repo `FMBase` from `git@git.coding.net:chongyingnvhai/FMSpec.git`
wuxianlvzhoudeMacBook-Pro:~ Allison$
此時我們再查看,就可以看到兩個了
wuxianlvzhoudeMacBook-Pro:~ Allison$ pod repo
FMBase
- Type: git (master)
- URL: git@git.coding.net:chongyingnvhai/FMSpec.git
- Path: /Users/wuxianlvzhou/.cocoapods/repos/FMBase
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/wuxianlvzhou/.cocoapods/repos/master

然后我們需要在遠程代碼托管上再創(chuàng)建一個,將本地庫上傳至遠程私有庫

2.cd進入到文件夾下,使用pod lib create <私有庫名字>命令, 克隆下來
注意:如果pod lib create <私有庫名字>出錯的話,建議這里看下終端環(huán)境,如果沒有錯誤,請直接跳過解決方案。
allisondeMacBook-Pro:~ allison$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
如果你和我一樣 是ruby2.5以上的環(huán)境,下面的命令執(zhí)行講話出現(xiàn)錯誤
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:27:in `<module:BuildSettingsArraySettingsByObjectVersion>': undefined method `to_set' for #<Array:0x007f925d88dc30> (NoMethodError) Did you mean? to_s
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:8:in `<class:XCBuildConfiguration>' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:4:in `<module:Object>'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:3:in `<class:Project>' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:2:in `<module:Xcodeproj>' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:1:in `<top (required)>'
from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/build_configuration.rb:194:in `<top (required)>' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object.rb:521:in `<top (required)>' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project.rb:5:in `<top (required)>'
from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Library/Ruby/Site/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Users/allison/Desktop/founderSpec/setup/ProjectManipulator.rb:30:in `run' from /Users/allison/Desktop/founderSpec/setup/ConfigureiOS.rb:73:in `perform' from /Users/allison/Desktop/founderSpec/setup/ConfigureiOS.rb:7:in `perform'
from /Users/allison/Desktop/founderSpec/setup/TemplateConfigurator.rb:85:in `run' from ./configure:9:in `<main>'
解決方案:
卸載一個已安裝的ruby2.5高版本
$ rvm remove <版本號>
例:rvm remove 2.5.1
通過rvm list known 查看目前的所有ruby版本

選擇低于ruby2.5的版本進行安裝
$ rvm install 2.4.1
再次執(zhí)行pod lib create <私有庫名字>命令,克隆操作將不會出錯。
wuxianlvzhoudeMacBook-Pro:~ Allison$ cd /Users/wuxianlvzhou/Desktop/remoteLib
wuxianlvzhoudeMacBook-Pro:remoteLib Allison$ pod lib create FMBase
Cloning `https://github.com/CocoaPods/pod-template.git` into `FMBase`.
Configuring FMBase template.
------------------------------
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
- http://guides.cocoapods.org/making/using-pod-lib-create.html
( hold cmd and double click links to open in a browser. )
What language do you want to use?? [ Swift / ObjC ]
> Objc
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> Yes
What is your class prefix?
> AA
Running pod install on your new library.
Analyzing dependencies
Fetching podspec for `FMBase` from `../`
Downloading dependencies
Installing FBSnapshotTestCase (2.1.4)
Installing FMBase (0.1.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `FMBase.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
[!] Automatically assigning platform ios with version 8.3 on target FMBase_Example because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
Ace! you're ready to go!
We will start you off by opening your project in Xcode
open 'FMBase/Example/FMBase.xcworkspace'
To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `http://guides.cocoapods.org/making/making-a-cocoapod`.
3.此時Xcode會自動打開一個工程,找到pods文件,把Pods-->Development Pods-->XMGFMBase-->XMGFMBase-->Classes-->ReplaceMe.m文件刪除,將三方替換過來.再次執(zhí)行pod install即可.

4.現(xiàn)在需要把整個FMBase文件夾提交到遠程私有庫,包括里面的測試工程一起提交.
wuxianlvzhoudeMacBook-Pro:Example Allison$ cd /Users/wuxianlvzhou/Desktop/1.0本地庫方案/remoteLib/XMGFMBase
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: FMBase/Classes/ReplaceMe.m
Untracked files:
(use "git add <file>..." to include in what will be committed)
Example/Podfile.lock
Example/Pods/
Example/FMBase.xcworkspace/
FMBase/Classes/Category/
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git add .
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git commit -m '**'
......
提交遠程庫前將FMBase.podspec文件修改
s.homepage = 'https://coding.net/u/chongyingnvhai/p/FMBase'
修改為:
s.homepage = 'https://git.coding.net/chongyingnvhai/FMBase.git'
提交前現(xiàn)在終端驗證下本地文件有沒有錯誤
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ pod lib lint
-> XMGFMBase (0.1.0)
FMBase passed validation.
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$
按回車,此時會自動驗證當前目錄下的ΧⅩΧⅩ.podspec文件,并且驗證里面的字段.看見FMBase passed validation即代表驗證成功.
注意:這里的 s.source_files = 'FMBase/Classes/*/' 目錄一定要是絕對的目錄,也就是說與.podspec同級目錄開始寫路徑.

將本地庫與遠程庫關(guān)聯(lián),并且上傳至遠程庫.
這里如果我們驗證遠程索引庫的話會報如下錯誤,所以接下來我們需要給我們的庫打tag.
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod spec lint
-> FMBase (0.1.0)
- ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
5.給我們的庫打tag,并推送至遠程庫.
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git tag
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git tag
0.1.0
wuxianlvzhoudeMacBook-Pro:XMGFMBase Allison$ git push --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 153 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git.coding.net:chongyingnvhai/XMGFMBase.git
* [new tag] 0.1.0 -> 0.1.0
6.驗證遠程倉庫
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod spec lint
-> FMBase (0.1.0)
Analyzed 1 podspec.
FMBase.podspec passed validation.
7.遠程驗證通過后,將自己的索引庫提交至遠程 (把FMBase.podspec文件push到遠程FMSpec私有庫中.)
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod repo push FMBase FMBase.podspec
Validating spec
-> FMBase (0.1.0)
Updating the `FMBase' repo
Already up-to-date.
Adding the spec to the `FMBase' repo
- [Add] FMBase (0.1.0)
Pushing the `FMBase' repo
To git.coding.net:chongyingnvhai/FMSpec.git
07b51f6..7bafcc3 master -> master
自己的私有索引庫


8.在終端直接檢索
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod search FMBase
-> FMBase (0.1.0)
FMBase框架
pod 'FMBase', '~> 0.1.0'
- Homepage: https://coding.net/u/chongyingnvhai/p/FMBase
- Source: https://git.coding.net/chongyingnvhai/FMBase.git
- Versions: 0.1.0 [FMBase repo]
至此本地的三方庫已經(jīng)變成私有庫了,我們來使用一下.
--------------------------------- 使用步驟: ----------------------------------
1.修改Podfile文件
use_frameworks!
target 'FMBase_Example' do
pod 'FMBase', :path => '../'
end
修改為
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'FMBase_Example' do
pod 'FMBase'
end
2.在終端執(zhí)行pod install
wuxianlvzhoudeMacBook-Pro:Example Allison$ pod install
Analyzing dependencies
Downloading dependencies
Installing FMBase (0.1.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
此時我們的遠程私有庫就可以通過pod的形式導(dǎo)入項目來使用了.but,but,but,如果我們用的是GitHub上的開元三方呢,Podfile文件如下
source 'git@git.coding.net:chongyingnvhai/FMSpec.git'
use_frameworks!
target 'FMBase_Example' do
pod 'FMBase'
pod 'AFNetworking'
end
我們再次執(zhí)行pod install的時候就會出現(xiàn)如下的錯誤
wuxianlvzhoudeMacBook-Pro:Example Allison$ pod install
Analyzing dependencies
[!] Unable to find a specification for `AFNetworking`
這是因為,我們執(zhí)行pod install的時候是從我們自己的私有庫里面搜索的,所以我們還需要將共有庫的地址加進來.
source 'git@git.coding.net:chongyingnvhai/FMSpec.git'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'FMBase_Example' do
pod 'FMBase'
pod 'AFNetworking'
end
這樣再次執(zhí)行就可以正確安裝了.
wuxianlvzhoudeMacBook-Pro:Example Allison$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (3.1.0)
Using FMBase (0.1.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
遠程私有庫的依賴+升級
以上完成了對遠程私有庫的設(shè)置,假如后期我們對該庫有修改,或者增加了一些其它的功能,我們需要對遠程的私有庫進行升級即可.一般我們都會有Subspecs子庫.例如我們熟知的AFNetworking
-> AFNetworking (3.1.0)
A delightful iOS and OS X networking framework.
pod 'AFNetworking', '~> 3.1.0'
- Homepage: https://github.com/AFNetworking/AFNetworking
- Source: https://github.com/AFNetworking/AFNetworking.git
- Versions: 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3,
3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4, 2.5.3, 2.5.2,
2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0,
2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4,
1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2,
1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
- Subspecs:
- AFNetworking/Serialization (3.1.0)
- AFNetworking/Security (3.1.0)
- AFNetworking/Reachability (3.1.0)
- AFNetworking/NSURLSession (3.1.0)
- AFNetworking/UIKit (3.1.0)
升級遠程私有庫的步驟:
1.在工程中加入新的類別

2.在控制臺執(zhí)行pod install
3.修改FMBase.podspec文件里面的 s.version = '0.2.0'
3.重寫打個tag 并push到遠端( git push --tags )
4.此時代碼已經(jīng)升級完成.
5.升級pod里面的Spec版本,先驗證通過

wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod spec lint
-> FMBase (0.2.0)
Analyzed 1 podspec.
FMBase.podspec passed validation.
6.往本地私有索引庫提交
在終端執(zhí)行 pod repo push FMSpec FMBase.podspec
wuxianlvzhoudeMacBook-Pro:FMBase Allison$ pod repo push FMSpec FMBase.podspec
Validating spec
-> FMBase (0.2.0)
Updating the `FMSpec' repo
Already up-to-date.
Adding the spec to the `FMSpec' repo
- [Update] FMBase (0.2.0)
Pushing the `FMSpec' repo
To git.coding.net:chongyingnvhai/FMSpec.git
c54796c..d3fde69 master -> master
在終端執(zhí)行 pod search FMBase可以看到搜索出來的結(jié)果.
-> FMBase (0.3.0)
FMBase框架
pod 'FMBase', '~> 0.3.0'
- Homepage: https://coding.net/u/chongyingnvhai/p/FMBase
- Source: https://git.coding.net/chongyingnvhai/FMBase.git
- Versions: 0.3.0, 0.2.0, 0.1.0 [FMSpec repo]
- Subspecs:
- FMBase/Category (0.3.0)
- FMBase/Base (0.3.0)
- FMBase/Tool (0.3.0)
- FMBase/Network (0.3.0)
這種對代碼結(jié)構(gòu)進行了歸類,目錄結(jié)構(gòu)更加簡潔明了.