Installation and usage of 2016 cocoapods and problems with version upgrades _ios

Source: Internet
Author: User
Tags install cocoapods aliyun

A. What is Cocoapods?

Cocoapods is a tool for managing third party open source libraries in iOS projects. Cocoapods Project source code in the GitHub management. The project began on August 12, 2011, and during the two-year period, it continued to remain active and updated. The development of IOS projects will inevitably use a third-party open source Library, the advent of cocoapods allows us to save the time to set up and update the Third-party Open Source Library, in the development of iOS often used in third-party libraries such as Afnetworking,asihttprequest, In the use of Third-party libraries, you have to, in addition to derivative source code, but, the integration of these dependent libraries need us to manually configure, and when these third-party libraries have been updated, you need to manually update the project. That's a lot of trouble. There are problems, natural solutions, cocoapods is to solve this problem and born. With Cocoapods, we can manage the third party's dependent libraries together, and the configuration and updates need to be done by simply a few lines of command.

Two. Download and installation of Cocoapods

The MAC system is already installed by default, and if you're unsure if you have ruby in your system, you can enter a command line in the terminal: Ruby-v View the current Ruby version. As shown in figure:

Once you're sure, you can download and install Cocoapods, just one line of commands. Enter the following command in The Terminator (that is, the terminal):

sudo gem install Cocoapods

However, after typing this command in the terminal, you will find that there is no response for half a day. The reason is that the wall blocked the cocoapods.org.

The solution is that we can use Aliyun ruby mirrors to access cocoapods. In the following order, in the terminal, and then typing the command:

First, check your ruby Source:

$gem sources-l

By default, the terminal should return the following information:

Current SOURCES * * *

https://rubygems.org/

Of course, this source is not accessible inside the wall. So we need to look for a mirror that can be accessed at home. At present, the author found is http://rubygems-china.oss.aliyuncs.com this aliyun mirror image, of course, with the passage of time, the future of this mirror may not be able to access, then can only be looked back.

Once you have confirmed that the mirror is available, you are ready to modify the ruby source. First, execute the following command to delete the original Ruby Source:

$gem sources--remove https://rubygems.org/

After you execute the command, you can see the following information at the terminal:

Https://rubygems.org/removed from sources

Next, add the available mirror sources you found:

$gem sources-a http://rubygems-china.oss.aliyuncs.com

At this point, if you perform the Gem sources-l command again, you can see that there is only Aliyun in the current mirror source. At this point you will be able to carry out the beginning of the sentence again:

$sudo Gem Install Cocoapods

If everything works, you should be able to see a piece of installation progress and finally a message:

3 Gems installed

Confirm that see this information, the first judge of the cocoapods can be used, you can use the Cocoapods search function to verify. In the terminal, enter:

Pod Search afnetworking;

May be stopped after execution

Setting up Cocoapods master repo then (for a long time), the following error occurs:

The solution is:

This means that cocoapods is not working properly, needs to update pod, downloads some of its dependencies, and enters in the terminal:

$ pod Setup

After a while, you will see the same red error message in the terminal.

This indicates that some environmental reasons have caused the pod to be updated, possibly because 1 gem versions are too low, 2 GitHub cannot be linked, and 3). The configuration information in the Cocoapods directory is incorrect. We can rule it out by one.

First, update the gem to the latest version and enter it in the terminal:

$ sudo gem update--system

Then check to see if you can ping the GitHub and enter it in the terminal:

$ ping github.com

Then view the POB repo list:

$ pod Repo list

Description Cocoapods in the download of its information into the ~/.cocoapods;

CD to the directory, with the DU-SH * command to view the file size, the results show 0 repos, indicating that the installation was not successful;

In the terminal input:

CD ~/.cocoapods

Enter Cocoapods file at Terminal input: Du-sh *

Re-execute POD setup, after a period of time prompted the setup completed, in the terminal input Pod list, display the installation list;

It's finally installed. Next again, enter:

Pod Search afnetworking

After entering it, it may report:

[!] Unable to find a pod with name, author, summary, or descriptionmatching ' afnetworking '

The solution is:

Input:

RM ~/library/caches/cocoapods/search_index.json

After one input: Pod search afnetworking

It's OK.

Third, the use of cocoapods

First come to your project file:

Location of the CD project file

Then, add a podfile file: Vim podfile

Then press I into insert mode, edit, and enter the following in the file:

Note that many of the previous version of Baidu entered the class capacity:

Platform:ios, ' 8.1 '
pod ' afnetworking ', ' ~> 2.0 '
It will report: [!] The dependency ' afnetworking (~> 3.0) ' is not used to any concrete target.
Now the official document for version upgrade is:

Platform:ios, ' 8.0 '

Target ' your project name ' Do

Pod ' afnetworking ', ' ~> 3.0 '

End

Note: ' Your project name ' is the ' xx.xcodeproj ' file in your project file, ' xx.xcodeproj ' removes the suffix name ' xx ' = = ' Your project name '

Press ESC to exit edit mode when the input is complete, and then enter: Wq to save and exit the file. At this point you can find a podfile file in the project directory, please note that this file must be in the same directory as the. xcodeproj.

At last:

Pod Install

No error will be allowed.

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.