Cocoapods installation and use detailed version

Installing cocoapods requires a ruby ​​environment, and mac comes with a ruby ​​environment.
Enter the following command in the terminal to check the ruby ​​version

ruby -v

If the version information is displayed, enter the following command in the terminal

sudo gem install cocoapods

After entering the above command, you are asked to enter the password, enter it directly and press Enter,
1

If you are in China, type this command in the terminal, and after entering the password, you will find that there is no response for a long time. For no other reason than that wall blocking cocoapods.org.
The solution is to use Taobao’s Ruby mirror to access cocoapods, and type commands in the terminal in the following order:

gem sources --remove https://rubygems.org/
//等到有反应后输入以下命令
gem sources -a http://ruby.taobao.org/

You can verify that the Ruby image is and only taobao through the following command.

gem sources -l

At this time, run again in the terminal:

sudo gem install cocoapods

If the ruby ​​version meets the requirements of the currently installed cocoapods, cocoapods will be installed after waiting for more than ten seconds, and no other settings are required.
If you want to display cocoapods menu items in xcode->product, you need to install the alcatraz plugin.
Install the alcatraz plug-in:
Enter the following command on the terminal to complete the installation:

curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/Scripts/install.sh | sh

After Alcatraz is successfully installed, open xcode, Window->package Manager, and the working window of Alcatraz will open.
Search for cocoapods in this window and click Install. After the installation is successful, restart xcode, it will be displayed in the product
2

If the ruby ​​version does not meet the requirements of the currently installed cocoapods, you need to update the ruby ​​version.

macxia installs ruby ​​environment
1. Install RVM
terminal input command: curl –L https://get.rvm.io | bash –s stable
Execute after the above instructions are executed: source ~/.rvm/scripts/rvm
check the version and check whether the installation is correct:rvm –v

2. Use rvm to install ruby ​​environment
Install version 2.2.2: Terminal input command: rvm install 2.2.2
During the period, you need to press the enter key to enter the administrator password, etc. After the
installation is successful, return to the beginning of the article and install cocoapods according to the cocoapods installation steps.

Cocoapods is simple and practical Add cocoapods support to the project Create a new podtest project
on the desktop as an example. Enter the directory where the project is located in the terminal
and enter the podtest folder through the cd command.
Use vim to create a Podfile file, and enter the command in the terminal: vim Podfile
platform:ios,'6.1'
pod 'SDWebImage','~>3.6' After
the input is complete, exit the insert mode, press Esc, and then enter: wq to save and exit.
This content comes from github SDWebImage, generally what kind of third-party library you need to add, the third-party library description document will have an introduction on how to add pods
At this time project directory, and the content of the file is the two sentences just entered
3
in the terminal Run the command: $pod install (the third-party library recorded in the Podfile will be installed)
depends on the network speed environment, the installation time may be longer. Note the last sentence, from now on use 'podsTest.xcworkspace',
4
there are 4 more Things, the Pods folder stores the third-party libraries you downloaded. After opening the project, you no longer use xcodeproj, but use xcworkspace... because you open the workspace workspace, you find that it contains two xcodeproj project files. One is its own project, and the other is the project that Pods manages third-party libraries.

Guess you like

Origin blog.csdn.net/qq_32796151/article/details/52525646