Cocoapods configuration, cocoapods

Source: Internet
Author: User
Tags install cocoapods

Cocoapods configuration, cocoapods
Ii. CocoaPods Installation

CocoaPods can be conveniently installed through RubyGems of Mac.

Open Terminal (the Terminal that comes with the Mac computer ):

 

(1). Set the ruby software source

This is because ruby's software source rubygems.org was blocked by tianchao because of Amazon's cloud services. I need to update the ruby source as follows:

1234567 gem sources -l # (View the current ruby source) gem sources --remove https:// Rubygems.org/# (remove the current ruby source) gem sources -a https:// Ruby.taobao.org/# (set the current ruby source to my tianchao) gem sources -l # (View the current ruby source again)

 

If Terminal outputs the following style, it indicates that the ruby software source has been set to OK.

123 *** CURRENT SOURCES *** https://ruby.taobao.org/

 

(2) Set gem to the latest version.
1234567 If gem is too old, you can try to use the following command to upgrade gem: Enter the following command in Terminal: sudo gem update --system After the upgrade is successful, the system prompts: Latest version currently installed. Aborting.

 

(3) run the CocoaPods installation command
1 sudo gem install  cocoapods

 

If the following error is reported:

123 ERROR:  While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/xcodeproj

 

Solution 1 (recommended ):

123 sudo gem install -n /usr/local/bin cocoapods pod setup

Note: When pod setup is executed, the Setting up CocoaPods master repo will be output, but it will take a long time. In this step, Cocoapods is downloading its information ~ /. In the cocoapods directory, if you have waited for too long, you can try cd to that directory and use du-sh * to view the download progress.

After the installation is successful, you will see: Setup completed

 

 

Solution 2 (not recommended, not tried ):

123456789 Run the following command and restart sudo nvram boot-args="rootless=0" sudo reboot Run this command to check the restart. sudo gem install cocoapods -V

After the solution is completed, run the CocoaPods command again.
1 sudo gem install  cocoapods

  

(3) After the installation is complete, search and try again.
12 Run (Case Insensitive)pod search AFNetworking

 

If it is OK, is it installed?

 

 

Note: Some common installation problems:

Question 1]

Pod search afnetworking:

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

 

Solution:

Step 1 remove index: rm ~ /Library/Caches/CocoaPods/search_index.json

Step 2: search again: pod search afnetworking

 

 

 

Question 2]

Sudo gem install cocoapods:

12 ERROR:  While executing gem ... (Errno::EPERM)Operation not permitted - /usr/bin/xcodeproj

Solution:

Step 1:

123 sudo gem install -n /usr/local/bin cocoapods pod setup

Step 2:

1 sudo gem install  cocoapods

  

 

 

 

Iii. Use of Cocoapods

1. Create a Podfile (all users who have used it know that they do not know how to create it on Baidu)

1234567891011121314151617 The content format of the Podfile file should be as follows: platform :ios, '8.0' # (Indicate your development platform and version, and '8. 0' is the latest version if you do not write it) pod 'AFNetworking''~> 2.5.3' # ('~> 2.5.3 'indicates the version number. If this parameter is left blank, the latest version is used) pod 'SDWebImage''~> 3.7.2' Then run the following command in the Terminal to enter the root directory (Project root directory) of the project: pod install In this way, AFNetworking and SDWebImage have been downloaded and the compilation parameters and dependencies have been set. Remember the following two points for future use: 1. From now on, you need to use the. xcworkspace file generated by Cocoapods to open the project, instead of using the previous. xcodeproj file. 2. Each time the Podfile file is changed, the pod update command needs to be re-executed.

 

Find third-party libraries:

If you do not know whether the database managed by cocoaPods has the library you want, you can search through the pod search Command, the following are all available libraries I found using pod search json:

You can enter the following in Terminal:

Pod search AFNetworking

After you press enter, you can see some library classes related to the keywords you search,


About Podfile. lock

After you run pod install, CocoaPods generates a file named Podfile in addition to Podfile. lock file, Podfile. lock should be added to version control and should not be added to this file. in gitignore. Because Podfile. lock locks the current version of each dependent database. If you execute pod install multiple times, the version will not be changed. Podfile. lock will be changed only after pod update. In this way, when multiple users collaborate, the versions of third-party libraries may be different when the third-party libraries are upgraded.

 

Related Article

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.