CocoaPods升級到1.9.1版本后,pod install 安裝庫的版本的時候報錯
查后得知
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'
最后,添加完成后,就變成兩個源了,可以酌情刪除一個
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