2016 Latest Cocoapods installation and error Solutions _ios

Source: Internet
Author: User
Tags install cocoapods

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.

Recently installed Cocoapods, on the Internet to find information, found that the article is either outdated, or a variety of errors. are copied to copy, there is no reliable, deliberately tidy up the latest tutorials, and test success. Taobao Gems Source has stopped maintenance and is now providing mirroring services by Ruby-china

First step: Install RVM,

Whether or not you need to upgrade RUBY,RVM allows you to have multiple versions of Ruby, and you can switch between multiple versions freely. If you have already installed skip to step 2nd (Rvm-v to see if it is installed)

$ curl-l Get.rvm.io | Bash-s stable
//need wait a minute
$ source ~/.BASHRC
$ source ~/.bash_profile

Wait for the terminal to load, and then enter

Rvm-v

If you can display a good version, the installation is successful.

Step Two: Install Ruby

Cocoapods current installation requires Ruby version greater than 2.2.2, or it will error: Error installing pods:activesupport requires Ruby version >= 2.2.2. The current MAC system defaults to 2.0, so it needs to be upgraded.

To view installed Ruby:

RVM List

If the installed version is greater than 2.2.2, go straight to step 3rd.

RUBY-V//can also view Ruby version
//list Ruby installable version information
RVM list known
RVM install 2.2.2//install a ruby version

This must be set to the default version

RVM Use 2.2.2--default

Step three: Replace the source

We need to modify the replacement source (due to the domestic wall) so we have to switch the source to Ruby-china. Execute the following command at the terminal

Now most of the online articles are this:

$ sudo gem update--system
$ gem Sources--remove https://rubygems.org/
//etc react before typing the following command
$ gem sources-a htt ps://ruby.taobao.org/

This is a big pit: it's going to be an error. _connect returned=1 errno=0 State=sslv3 Read Servercertificateb:certificate verify failed (https:// ruby.taobao.org/specs.4.8.gz)

This is because the Taobao Gems source has stopped maintenance and is now provided by the Ruby-china mirroring service, and the correct action is:

$ sudo gem update--system
$ gem Sources--remove https://rubygems.org/
$ gem Sources--remove Https://ruby.taobao org////If you have installed the mirror of Taobao//
etc, and then typed the following command
Gem sources-a https://gems.ruby-china.org/

To verify that your Ruby mirror is and is only Ruby-china, you can view it with the following command:

$ gem sources-l

Only the following text appears in the terminal to indicate that your command was successful:

Current SOURCES * * *

https://gems.ruby-china.org/

# Make sure only gems.ruby-china.org

Fourth Step: Install Cocoapods

sudo gem install-n/usr/local/bin cocoapods

One more word, perfect solution.

sudo xcode-select--switch/applications/xcode.app

Enter the following command in the terminal to complete the installation:

Pod Setup

It takes a little time to finish, I'm hanging up anyway. Wait a night.

If the installation fails ~/.cocoapods the inside is empty, you will need to reset the setup

The order is as follows:

Pod repo remove master
pod Setup

After the completion of this folder is about 100 m, it will take more time, please be patient.

You've successfully installed Cocoapods here.

To determine whether the cocoapods can be used, you can use the Cocoapods search function to verify. In the terminal, enter:

$ pod Search afnetworking

After a while (probably longer), you will see some red error messages in the terminal, as follows:

Setting up Cocoapods master Repo

[!] /usr/bin/gitclone ' Https://github.com/CocoaPods/Specs.git ' master--depth=1

Cloning into ' master ' ...

Error:rpc failed; result=52, HTTP code = 0

Fatal:the remote end hung up unexpectedly

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.

When the above command is typed, this is the way on the small end (because it is too long to intercept only the previous part):

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

The results showed 0 repos, indicating no successful installation;

Delete the. cocoapods directory and download the pod update again:

$ cd ~/.cocoapods/
$ sudo-rm-rf ~/.cocoapods/

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

When the above command is typed, this is the way on the small end (because it is too long to intercept only the previous part):

See here, your heart will say, holy cow! It's so cool, it's finally downloaded and installed! Next see how to use it.

Let's start by creating this magical podfile. In the terminal, enter (CD command) your project directory, and then in the current directory, using Vim to create Podfile, run:

$ vim Podfile

Then enter the following text in the Podfile file:

Note that the format entered in the Podfile has changed.

Platform:ios, ' 8.0 '

Target ' your project name ' Do

Pod ' afnetworking ', ' ~> 3.1.0 '

End

Then save the exit. In the VIM environment, the Save Exit command is:

: Wq

At this point, you will find a file with the name Podfile in your project directory, and the content of the file is what you just entered. Note that the Podfile file should be in the same directory as your project file. Xcodeproj.

At this point, you can use Cocopods to download the Afnetworking class library. Or in the current project directory in the terminal, run the following command:

$ pod Install

Note the last sentence, meaning: Open the project later with the Cocoapodsdemo.xcworkspace open, rather than the previous. xcodeproj file. Otherwise you cannot associate the class library of pod down.

The above is a small set up to introduce 2016 of the latest Cocoapods installation and error solutions, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.