Troubleshoot the CocoaPods Trunk CDN connection failure


CocoaPods uses trunk CDN (cdn.cocoapods.org/) as the spec source by default since version 1.8. Avoid the problem of having to clone a large Specs warehouse locally, causing full updates every time you update it. However, for some reason even trunk CDN access is restricted in China.

The common problem is that pod install reports the error CDN: Trunk URL downloaded and POD repo update CDN: Trunk repo update failed

Here are a few solutions.

Install CocoaPods

Make sure CocoaPods is installed before you perform the following steps.

Execute pod –version to check if CocoaPods is installed and to see the version number.

Install CocoaPods: Open the Terminal and run the following command:

sudo gem install cocoapods
Copy the code

See CocoaPods getting Started

Note: If you can’t download CocoaPods due to network problems, you can use the Ruby Gems image source:

  • Tsinghua Gems mirror station: mirror.tuna.tsinghua.edu.cn/help/rubyge…

  • Ruby China: gems.ruby-china.com

Failed to connect to the Trunk CDN

Plan 1: Use a proxy

Using either older CocoaPods or mirroring sources is not an optimal solution. In order to take full advantage of CocoaPods features, it is recommended to use proxies to solve the problem of not being able to connect to the Trunk CDN.

Plan 2: Use older Versions of CocoaPods

The 1.7.5 version of CocoaPods uses Specs as a repo source by default, and you can uninstall and reinstall older versions of CocoaPods.

  • Uninstall:
sudo gem uninstall cocoapods
Copy the code
  • Install CocoaPods 1.7.5:
Sudo gem install Cocoapods -v 1.7.5Copy the code

Scheme 3: Manually switch to the official Git source or image source

Do not recommend this scheme, more cumbersome.

  1. Check the source currently in use

    To implement pod repo list view the machine what are the source, if there is a master source (URL: https://github.com/CocoaPods/Specs.git), and a trunk source (URL: https://cdn.cocoapods.org/), you do not need to operate the following step 2, can be directly executed pod repo remove trunk delete trunk CDN source.

    If version 1.9.1 or later is used, only one Trunk CDN source exists. In this case, you need to manually add the Git source

  2. Add the source

    • Add the official CocoaPods Git source

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

    • Add tsinghua CocoaPods image source

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

  3. Run pod repo update –verbose

  4. Specify the source in the iOS project root Podfile

    If you can’t find your Podfile, CD it to the root of your iOS project and execute Pod Init

    Add a line source https://xxxxx.git to the first line of your Podfile (where the URL is the URL of the source added in the previous step)

    Example: Use Qinghua source

    source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
    
    target 'MyProject' do
      use_frameworks!
    end
    Copy the code

    If you don’t specify a source in your Podfile, CocoaPods above 1.8 will automatically re-add and use trunk CDN sources, so you need to specify an explicit source for each project’s Podfile, which is cumbersome.