The most detailed cocoapods installation tutorial in history (text) _ios

Source: Internet
Author: User

Although the internet about Cocoapods installation tutorials are numerous, but I still have a lot of errors in the installation process, so we can take down the steps to install, I believe it will be very useful.

Objective

Using a Third-party class library in an iOS project can be very common, but configuring them properly is sometimes a chore, and fortunately cocoapods is a good solution.

What is Cocoapods

Cocoapods is a third Class library management tool under OS X and iOS, and through the Cocoapods tool we can add a dependency library called "Pods" to the project, which must be supported by Cocoapods itself, and can easily manage its version.

The meaning of cocoapods is embodied in two aspects. First, it can automatically complete a variety of configurations for us when introducing a Third-party library, including configuring the compile phase, connector options, and even-FNO-OBJC-ARC configurations in the ARC environment. Second, using cocoapods makes it easy to find new Third-party libraries, which are more "standard" than those found on the web, so that we can find a really useful class library.

Next we will introduce the use of cocoapods.

Cocoapods the core Components

The Cocoapods is written in Ruby and is divided into several gem packages.

The cocoapods of the most important packages in parsing execution are: Cocoapods/cocoapods, Cocoapods/core, and Cocoapods/xcodeproj.

Cocoapods/cocoapod: This is a user-oriented component that will be activated whenever a pod command is executed. It includes all the functionality of the utility cocoapods and can also invoke other gem packages to perform the task.

The Cocoapods/core:core gem provides processing of cocoapods-related files (mainly podfile and podspecs).

Podfile: This file is used to configure the Third-party libraries needed for the project, which can be highly customizable. In this article, we mainly do the action here.

Podspec: This file describes how a library will be added to the project. The. podspec file identifies the source files, dependent libraries, compilation options, and other third-party libraries needed for the Third-party library.

Cocoapods/xcodeproj: This package is responsible for working with engineering files, which create and modify. xcodeproj files and. xcworkspace files. It can also be used as a stand-alone package, and you can consider using cocoapods/xcodeproj when you want to write a script that modifies the project file.

Cocoapods Installation Steps

1. Upgrade Ruby Environment

Terminal input:$gem update --system

This will appear

Error:while Executing gem ... (Gem::filepermissionerror)

You are don ' t have write permissions for the/library/ruby/gems/2.0.0 directory.

zijingmacbook-pro:~ shiyunlei$ sudo gem update-system

This is because you don't have the authority to update Ruby.

This time you can use at the end: $sudo gem Update-system to upgrade

This time indicates that Ruby upgrade is complete.

2, install cocoapods when we want to visit cocoapods.org, the site may be our big celestial wall, so download installation may be turtle speed, fortunately we can use Taobao Ruby mirror to access the site, the following methods:

Copy Code code as follows:

Gem Sources--remove https://rubygems.org/
Gem Sources-a http://ruby.taobao.org/

You can use the following command (in the Red section) to see whether the replacement mirror succeeds (as shown in the following illustration):
$ gem sources-l

3, install Cocoapods, in the terminal input command

$sudo gem install cocoapods

This time will prompt you to enter the password, note: In the terminal input password does not have the prompt, the cursor also does not move, must notice

Start the installation, as shown in the following figure: PS: This process may take a long time

Installation success is as follows:

4. Search the class library name using the search command:

$pod search AFNetworking

If cocoapods support, it will output all the class library versions and information that are searched, as well as the configuration in Podfile, and the terminal return information is as follows:

-> afnetworking (2.3.1)

A delightful IOS and OS X networking framework.

Pod ' afnetworking ', ' ~> 2.3.1 ' (this statement is a command that needs to be entered when editing Podfile, that is, how to install instructions to download the related class library)

-Homepage:https://github.com/afnetworking/afnetworking

-Source:https://github.com/afnetworking/afnetworking.git

-versions:2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0,

2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-rc2, 2.0.0-rc1, 1.3.4, 1.3.3,

1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2, 1.0rc1,

0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]

-Sub Specs:-Afnetworking/serialization (2.3.1)-

Afnetworking/security (2.3.1)-afnetworking/reachability (2.3.1)-

Afnetworking/nsurlconnection (2.3.1)-Afnetworking/nsurlsession (2.3.1)

-Afnetworking/uikit (2.3.1)

-> Afnetworking+autoretry (0.0.5)

Auto Retries for afnetworking requests

Pod ' afnetworking+autoretry ', ' ~> 0.0.5 '

-Homepage:https://github.com/shaioz/afnetworking-autoretry

-Source:https://github.com/shaioz/afnetworking-autoretry.git

-versions:0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1 [master repo]

5, need to create a podfile file in the project,

To use the command:

$cd /Users/shiyunlei/Desktop/CocoapodsSample(Into the engineering directory, the CD behind the project Path)

$ touch Podfile(Create Podfile file)

Then use Vim to edit the Podfile file, using the command:

$ vim Podfile
Enter the following interface

Then press the "I" key on the keyboard to become the following state, at which point the Podfile file can be edited:

$platform: iOS, ' 7.0 '

$ Pod ' afnetworking ', ' ~> 2.3.1 '

Press ESC when the edit is complete.

In the Press ":", this time enter Wq, click Enter, save and exit.

When you open the Podfile file, you will see that you have added a line of statements that you just entered in the terminal, as shown below

Then install the corresponding third party library in the Terminal input command

$pod Install

Because this process needs to download the corresponding class library, so time and speed related.

After successful installation, the screenshot is as follows:

This time you'll see. Open engineering needs to be opened from the type to the project name. xcworkspace file.

The most detailed cocoapods installation tutorials in history are over, and if you have any questions, check out the relevant articles below.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.