CocoaPods 執行 pod install
會安裝 github.com
上的包,但 github.com
很不穩定。
一個解決方案是,使用腳本將 github.com
的資源轉換爲其餘域的資源。python
CocoaPods 從 1.7.2 版本開始使用 https://cdn.cocoapods.org/
代替原有的 https://github.com/CocoaPods/Specs.git
,
這樣能夠按需下載須要的包定義,而不用一次性下載整個 Specs
庫(整個庫是 3GB 左右),參考 CocoaPods 1.7.2 — Master Repo CDN is Finalized!。ios
source 'https://github.com/artsy/Specs.git' - source 'https://github.com/CocoaPods/Specs.git' + source 'https://cdn.cocoapods.org/'
腳本是使用 python
寫的,很簡單,放在 https://github.com/senntyou/CocoaPods-Specs-Modify
,如要使用,須要先克隆到本地。git
git clone https://github.com/senntyou/CocoaPods-Specs-Modify.git cd CocoaPods-Specs-Modify python modify.py
modify.py
腳本中,默認 specsDir
取 ~/.cocoapods/repos/trunk/Specs/
,targetSite
取 github.com.cnpmjs.org/
,能夠根據須要更改,再運行腳本github
# Specs目錄 specsDir = os.path.expanduser('~') + '/.cocoapods/repos/trunk/Specs/' # github 域名 githubSite = 'github.com/' # 替換域名 targetSite = 'github.com.cnpmjs.org/'
好比,原來的包定義是npm
{ "name": "MJRefresh", "version": "3.6.1", "summary": "An easy way to use pull-to-refresh", "homepage": "https://github.com/CoderMJLee/MJRefresh", "license": "MIT", "authors": { "MJ Lee": "richermj123go@vip.qq.com" }, "platforms": { "ios": "9.0" }, "source": { "git": "https://github.com/CoderMJLee/MJRefresh.git", "tag": "3.6.1" }, "source_files": "MJRefresh/**/*.{h,m}", "resources": "MJRefresh/MJRefresh.bundle", "requires_arc": true }
更改後的包變成ui
{ "name": "MJRefresh", "version": "3.6.1", "summary": "An easy way to use pull-to-refresh", "homepage": "https://github.com.cnpmjs.org/CoderMJLee/MJRefresh", "license": "MIT", "authors": { "MJ Lee": "richermj123go@vip.qq.com" }, "platforms": { "ios": "9.0" }, "source": { "git": "https://github.com.cnpmjs.org/CoderMJLee/MJRefresh.git", "tag": "3.6.1" }, "source_files": "MJRefresh/**/*.{h,m}", "resources": "MJRefresh/MJRefresh.bundle", "requires_arc": true }
github.com
變成 github.com.cnpmjs.org
code
更多博客,查看 https://github.com/senntyou/blogsorm
做者:深予之 (@senntyou)cdn
版權聲明:自由轉載-非商用-非衍生-保持署名(創意共享 3.0 許可證)blog