If this article helped you, don’t forget to like, follow, and bookmark biubiubiu

The words written in the front:

In the event of interruption, slow progress, and various failures in any of the following steps, please strictly observe the following principles:

1. Try again, try again, try again, maybe just a few more times. 2. Switch to mobile phone mobile network (it has been verified many times and feasible); 3, the above method is not good, then go to the channel of scientific Internet, pay attention to switch into the global mode (it is suggested to put the last try, anyway, I did not try, are listening to others say); 4, or failure, and so on, in the early morning or so will be much better (has been verified many times, feasible); 5, to here or not, then we have to consider the problem of their own character;Copy the code
Other questions, please search for yourself

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — –

The body of the

Yourself many times CocoaPod, met all kinds of annoying problem among them, has also encouraged their learned a lot in the continuously grope, to summarize, for everybody to learn and study, the following process by himself, new tests, smooth all the way without any errors (please in strict accordance with the following method to do), there is bad network download may interrupt error, as long as the new implementation One command is all it takes.

CocoaPods introduction:

CocoaPods is a Ruby tool for managing third-party open source libraries in iOS projects. It allows you to centrally manage your third-party open source libraries and saves you time setting up and updating your third-party open source libraries.

CocoaPods installation:

Install CocoaPods as soon as possible. If there is a space in the middle of the command, you are advised to copy and paste it.

Since the Mac came with Ruby, we just opened the terminal and started. However, by default, our MAC Ruby environment is relatively low (2.0.0 or higher), but now we need to install CocoaPods 2.2.2 or higher, so we will upgrade Ruby first.

Open a terminal: >_
1. View the current Ruby version
ruby -v
Copy the code
2, Upgrade Ruby environment, first need to install RVM (the first step is to download some things wait about two minutes)
curl -L get.rvm.io | bash -s stable 
source ~/.bashrc
source ~/.bash_profile
Copy the code
3. View the RVM version
rvm -v 
Copy the code

The following is displayed (or another version)

RVM 1.29.3 (Latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]Copy the code
List the installable versions of Ruby
rvm list known
Copy the code

According to the following

# MRI Rubies[Ruby -]1.8.6[-p420][Ruby -]1.8.7[-head] # Security Released on 1.9.1 head [ruby -] [- p431] [ruby -] 1.9.2 [- p330] [ruby -] 1.9.3 [- p551] [ruby -] 2.0.0 [- p648] [ruby -] 2.1. [10] [ruby -]. [10] [ruby -] 2.3 2.2 [8] [ruby -] 2.4. [9] [ruby -] 2.5. [7] [ruby -] 2.6 [5] [ruby -] 2.7 [0] / / / here, here, here, ruby - head...Copy the code
5. Install a Ruby version (I chose version 2.5.1 here, but you can choose another)
RVM install 2.6.3 // Note: During the installation process, press Enter twice, after the second press, you need to Enter the computer access password (not visible, just Enter); // If you do not have Xcode and Command Line Tools for Xcode installed on your computer and Homebrew automatically downloads and installs them, it is recommended to install them in advance.Copy the code

There will be many errors, most of which will be caused by not installing Homebrew, so it is better to install it in advance

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code
6. Set to the default version
RVM use 2.6.3 - defaultCopy the code
7, replace the source
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
Copy the code
8. To verify that your Ruby image is and is ruby-China only, run the following command
gem sources -l
Copy the code

If the following results are correct, if there are other results, please solve by baidu

*** CURRENT SOURCES ***
https://gems.ruby-china.com/
Copy the code
9. Install CocoaPods now
sudo gem install -n /usr/local/bin cocoapods
Copy the code
10. If you have multiple xcodes installed, use the following command to select the latest version of Xcode:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Copy the code
11. Install the local library
pod setup
Copy the code
12. After executing the above commands
Setting up CocoaPods master repo $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress Cloning into 'master'... remote: Counting objects: 1879515, done. remote: Compressing objects: 100% (321/321), done. Receiving objects: 21% (404525/1879515) and 73.70 MiB | KiB / 22.00Copy the code

Then there’s the long wait, but of course it’s faster when the Internet is good

Here we go. Pay attention

On the latest MacOS Catalina, run the pod setup command. Don’t worry, we manually install the local library, the speed is absolutely fast command line to perform the following operations

Git clone https://github.com/CocoaPods/Specs.git ~ /. Cocoapods/repos/trunk note: note: note: it is important to reiterate: Use this command to execute after waiting for a period of time is likely to fail, the basic reason is the network problem, please do not worry, according to my friends and I have tested many times, the network speed will only be ideal when using the mobile phone network or in the early morning (about a few minutes is OK, Otherwise, it doesn't matter if you have good Internet bandwidth.) If you can't stay up at night, can't wake up in the morning, and your cell phone data is dead, read on! Well...Copy the code

Or use the following, domestic mirror, speed just

git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git  ~/.cocoapods/repos/trunk
Copy the code

The directory structure is shown below. If not, move it manually

And if that doesn’t work

Cocoapods sudo gem install cocoapods --pre -fr ~/. Cocoapods /repos/master - fr ~ / Library/Caches/CocoaPods / / / to the setup, Git clone pod setup --verbose // Remove trunk pod repoCopy the code

CocoaPods | MacOS-Mojave

If the installation is not successful please refer to here

Skip the following paragraph and go straight to step 13:

To view the file download progress, open another terminal window (shortcut key: Select the terminal and press Command+N), and enter the following two commands: Enter

cd ~/.cocoapods

du -sh *
Copy the code

Du -sh * will display the size of the downloaded file. You can run it several times to check the progress of the download. If the size of the downloaded file is still there, but it becomes 0 later, it may be a network problem, the download has been interrupted, you need to end the command and restart the pod setup

13, after the download and installation is complete, you can execute the following command to check whether it is available (the first use may take a while)
pod search AFNetworking
Copy the code
14. Specific use of CocoaPods

Create a new Xcode project and use terminal CD to go to the project directory

Create Podfile:

pod init
Copy the code

You will then see a Podfile in the project directory

Open Podfile:

open Podfile
Copy the code

Add:

pod 'AFNetworking'
Copy the code

Exit after saving

Start downloading:

pod install
Copy the code

I here the first time will be wrong, as long as again (see character) implementation is good, may be the network or other reasons.

To the Success!

If there is a problem, you can first retrieve the cause of the error and the solution