美文网首页
[CocoaPods]解决trunk CDN 连接不上的问题

[CocoaPods]解决trunk CDN 连接不上的问题

作者: 汴城码农 | 来源:发表于2023-03-21 15:04 被阅读0次

CocoaPods升级到1.9.1版本后,pod install 安装库的版本的时候报错


截屏2023-03-22 14.06.21.png

查后得知

CocoaPods升级后podfile的默认源为trunk, 而非master,podfile的数据源变成了**https://cdn.cocoapods.org/

那问什么要默认用这个数据源呢,科普一下:
CDN的全称是Content Delivery Network,即内容分发网络。CDN是构建在现有网络基础之上的智能虚拟网络,依靠部署在各地的边缘服务器,通过中心平台的负载均衡、内容分发、调度等功能模块,使用户就近获取所需内容,降低网络拥塞,提高用户访问响应速度和命中率。CDN的关键技术主要有内容存储和分发技术
CocoaPods 自 1.8 版本开始默认使用 trunk CDN (https://cdn.cocoapods.org/) 作为 spec 的源,本意是非常好的,避免了需要本地 clone 一份庞大的 Specs 仓库导致每次 update 都要全量更新的问题。然而不知为何国内连 trunk CDN 都被限制访问了。

解决办法我的情况无效,仅供参考

在执行以下步骤之前,请确保已安装 CocoaPods
pod --version
1,检查当前使用的源
pod repo list

先执行 pod repo list 查看本机的源有哪些,如果存在一个 master 源 (URL: https://github.com/CocoaPods/Specs.git) 以及一个 trunk 源 (URL: https://cdn.cocoapods.org/),则无需操作下面的第二步,可直接执行 pod repo remove trunk 删除 trunk CDN 源。

若使用 1.9.1 或以上版本,应该只存在一个 trunk CDN 源,此时需要手动添加 Git 源

2,添加源

添加 官方 CocoaPods Git 源

执行 pod repo add cocoapods https://github.com/CocoaPods/Specs.git

添加 清华 CocoaPods 镜像源

执行 pod repo add tuna https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git

3,执行 pod repo update --verbose

在 iOS 项目根目录下的 Podfile 文件里指定源

另外,若找不到 Podfile,请先 cd 进 iOS 项目的根目录,执行 pod init

往 Podfile 的第一行添加一句 source https://xxxxx.git (其中的 URL 为上一步添加的源的 URL)

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

target 'MyProject' do
  use_frameworks!
end

解决的核心就是添加 镜像源

pod repo add tuna https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git无效
CocoaPods 是一个 Cocoa 和 Cocoa Touch 框架的依赖管理器,具体原理和 Homebrew 有点类似,都是从 GitHub 下载索引,然后根据索引下载依赖的源代码。

对于旧版的 CocoaPods 可以使用如下方法使用 tuna 的镜像:

$ pod repo remove master
$ pod repo add master https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
$ pod repo update

新版的 CocoaPods 不允许用pod repo add直接添加master库了,但是依然可以:

$ cd ~/.cocoapods/repos 
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

最后进入自己的工程,在自己工程的podFile第一行加上:

source 'https://xxxxxxxxxxxx/CocoaPods/Specs.git'

最后,添加完成后,就变成两个源了,可以酌情删除一个


截屏2023-03-22 15.18.26.png
pod repo remove trunk

貌似, Podfile必须要添加指定源,否则在pod install的时候,又下载了CDN的trunk源

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

target 'MyProject' do
  use_frameworks!
end

所有源汇总

github(老版本CocoaPods就是这种,缺点速度慢)
https://github.com/CocoaPods/Specs.git
清华
https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
CDN (目前就是不好用)
https://cdn.cocoapods.org

相关文章

网友评论

      本文标题:[CocoaPods]解决trunk CDN 连接不上的问题

      本文链接:https://www.haomeiwen.com/subject/vgemrdtx.html