解决 CocoaPods 命令 pod install 装置 github.com 上的包十分迟缓或者失败

CocoaPods 执行 pod install 会装置 github.com 上的包,但 github.com 很不稳固。
一个解决方案是,应用脚本将 github.com 的资源转换为其余域的资源。

CocoaPods v1.7.2

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!。

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 clone https://github.com/senntyou/CocoaPods-Specs-Modify.gitcd CocoaPods-Specs-Modifypython modify.py

modify.py 脚本中,默认 specsDir~/.cocoapods/repos/trunk/Specs/targetSitegithub.com.cnpmjs.org/,能够依据须要更改,再运行脚本

# Specs目录specsDir = os.path.expanduser('~') + '/.cocoapods/repos/trunk/Specs/'# github 域名githubSite = 'github.com/'# 替换域名targetSite = 'github.com.cnpmjs.org/'

示例

比方,原来的包定义是

{  "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}

更改后的包变成

{  "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

后续

更多博客,查看 https://github.com/senntyou/blogs

作者:深予之 (@senntyou)

版权申明:自在转载-非商用-非衍生-放弃署名(创意共享 3.0 许可证)