IOS install CocoaPods detailed process

Reprint please contact the author to obtain authorization, and marked the author, thank you, there is a moral conscience!

I. Introduction

  • What is CocoaPods CocoaPods is OS X and iOS under a third class library management tools, through CocoaPods tools we can add to the project called “dependent Pods library” (these libraries must be supported by the CocoaPods itself), and can easily manage the version.
  • The benefits of cocoaPods 1, in the introduction of the third party library, it can automatically complete a variety of configurations for us, including the configuration of the compilation phase, connector options, and even the ARC environment -fno-objc-arc configuration.
    2, CocoaPods can easily find a new third party library, the library is a “standard”, and not easily find online, so that we can find a really good library.
IOS install CocoaPods detailed process

Two, Cocoapods installation steps

Note: when you enter a command at the terminal, take the back part of the input

1, upgrade the Ruby environment

Terminal input: $gem update --system

At this time will appear

IOS install CocoaPods detailed process
no permission to upgrade Ruby tips

This is because you do not have permission to upgrade Ruby

This should be entered: $sudo gem update --system

At this time there will be

IOS install CocoaPods detailed process
input password

Then enter the password, note: enter the password when there is no response, the cursor will not move, even though you are the input, the loss of direct return.
wait a minute if there is

IOS install CocoaPods detailed process
upgrade Ruby success

Congratulations, upgrade Ruby is successful.

2, replace the Ruby image

First remove the existing Ruby image

Terminal input: $gem sources --remove

Then add the latest image source (Taobao’s Ruby image is not updated)

Terminal input: $gem source -a

After the completion of the implementation of the input gem sources -l to view the current image

Terminal input: $gem sources -l

If the result is
successfully added, otherwise continue to add -a source $gem

3, install CocoaPods

Next install

Terminal input: $sudo gem install cocoapods

If this

IOS install CocoaPods detailed process
installation error

shows no permissions required to enter

Terminal input: $sudo gem -n /usr/local/bin install cocoapods

The installation is as follows:

IOS install CocoaPods detailed process
installed successfully

To do this after pod setup (PS: this process is long, be patient)

Terminal input: $pod setup

Then you will see the emergence of the Setting up master repo, stuck motionless, indicating that Cocoapods in its information to download to ~/.cocoapods CocoaPods.
command+n you can create a terminal window, execute the CD ~/.cocoapods/ into the folder, then the implementation of Du * -sh to view the file size, every few minutes at a time, the final directory size is more than and 900 M (I 930M) when Setup completed
that has been completed.

Ha ha, it is not easy, and finally come to this step, and finally completed the installation, so in the end can not use it? Let’s look down!
note: all of the above steps are configured for this computer CocoaPods environment, the following is the real CocoaPods installed in your project.

4, the use of CocoaPods

1, we first look at the three party Library
Terminal input: $pod search AFNetworking

At this time there may be

IOS install CocoaPods detailed process
search tips

This is because the time before the pod
search search_index.json
to generate the cache file to execute RM ~/Library/Caches/CocoaPods/search_index.json to delete the file and then enter the
pod search AFNetworking
Creating to search that will prompt search index for spec repo’master’..
will wait while the search results appear again as follows:

IOS install CocoaPods detailed process
AFNetworking search results

The emergence of a note on the successful search, see above in this sentence:
pod’AFNetworking’,’~&gt 3.1.0′;
this sentence for us to use, this is the key field to add CocoaPods three party libraries

2, create a Podfile file in the project

To create a Podfile file in your project, you must first enter the project directory

Terminal input: $CD /Users/liyang/Desktop/CocoaPodsTest

Come in and create

Terminal input: $touch Podfile

Then you can see more than one Podfile file in your project directory

3, edit the name and version of the third party library you want to import

Use VIM to edit Podfile files

Terminal input: $VIM Podfile

Enter the following interface:

IOS install CocoaPods detailed process
edit Podfile file

After coming in, followed by the keyboard on the English’i’key
below “Podsfile” 0L, 0C will become – INSERT –
and then you can edit the text, enter the following text

Platform: IOS,'7.0'target do pod "AFNetworking", "~> 3.1.0" end'MyApp'

Explain that’MyApp’is your project name: IOS, platform,’7.0′ represents the current AFNetworking support the lowest iOS version is iOS 7,’~> 3.1.0’to download the AFNetworking version is version 3.1.0 and above

After editing as follows:

IOS install CocoaPods detailed process
editing completed

at this time to quit, how to quit? Follow me, first press the upper left corner of the ESC key, then press: key, and then enter the WQ, click enter, save and exit.

At this time, you will find that the contents of the file in your project directory named Podfile are what you just typed.

4, download the library to Xcode
Terminal input: $pod install

This began to download, it takes some time, the following interface shows that the installation of

IOS install CocoaPods detailed process
installed successfully

This time to close all of the Xcode window, and then open the project directory will see more than a suffix named.Xcworkspace file.

IOS install CocoaPods detailed process
project directory

After opening the project double-click on the file to open, and is no longer open the.Xcodeproj file.
into the project after the introduction of the header file is no longer #import “AFNetworking.h”, but #import < AFNetworking.h>

Finally finished, almost 1 points, and do not ask for praise, not to reward, but can help more people!
if there is what is wrong or inadequate, but also hope readers can give opinions or suggestions