解决 CocoaPods 命令 pod install 安装 github.com 上的包非常缓慢或者失败

????????关注后回复 “进群” ,拉你进程序员交流群????????

作者:深予之 (@senntyou)

来源:

https://segmentfault.com/a/1190000040143548

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.git

cd CocoaPods-Specs-Modify

python modify.py

modify.py 脚本中,默认 specsDir 取 ~/.cocoapods/repos/trunk/Specs/targetSite 取 github.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)

来源:

https://segmentfault.com/a/1190000040143548

-End-

最近有一些小伙伴,让我帮忙找一些 面试题 资料,于是我翻遍了收藏的 5T 资料后,汇总整理出来,可以说是程序员面试必备!所有资料都整理到网盘了,欢迎下载!

点击????卡片,关注后回复【面试题】即可获取

在看点这里好文分享给更多人↓

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值