A, install,

Installation command:

sudo gem install cocoapods
Copy the code

This needs to access outside the wall. If it cannot be installed normally, please refer to the following source change process.


Steps:

(1) Remove the built-in source

$ gem sources --remove https://rubygems.org/
Copy the code

(Remove native Ruby source)

$ gem sources -a https://ruby.taobao.org/
Copy the code

(Change the source of Chinese Taobao, please note HTTPS, HTTP has been deprecated, of course, there is also a source of Ruby China, just change the link to: gems.ruby-china.com/, different feelings for you)

(2) Change the source

Use the following command to check whether the source is changed

$ gem sources -l
Copy the code

Display:

*** CURRENT SOURCES ***https://ruby.taobao.org/
Copy the code

Replacement succeeds

(3) Installation

$ sudo gem install cocoapods
Copy the code

(4) View the version

pod --version
Copy the code

Check whether Cocoapods is successfully installed. If the version number is displayed, the installation is successful

Second, the use of

Go to the project directory using the command line tool:

vim Podfile
Copy the code

For example, import navigation:

Confirm that you’ll be able to retrieve all the items you’d like to download for your next project. For example, you’ll need to import the third-party library for navigation 1.1.0

pod 'Masonry'
Copy the code

I don’t know which version can be written like this, but I recommend that you write the version number or use the command

pod search Masonry
Copy the code

View the navigation version save. Close the Podfile and type:

pod install
Copy the code

Third-party libraries are downloaded into the project. If there are many third party libraries, you can post the names of other libraries under POD ‘navigation’. For example:

pod 'Masonry'
pod 'AFNetworking'
Copy the code

Save and close Install, and the third-party libraries will be downloaded to the project’s Pods folder. That concludes the introduction to CocoaPods.


Three, unloading

1, uninstall command:

$ sudo gem uninstall cocoapods
Copy the code

Cocopods = cocopods = cocopods = cocopods

$ gem list --local | grep cocoapods
Copy the code

The following is displayed:

Plugins (0.4.2) cocoapods- Search (0.1.0) cocoapods-stats (0.6.2) Cocoapods-trunk (0.6.4) Cocoapods-try (0.5.1)Copy the code

3. Delete one by one:

$ sudo gem uninstall cocoapods-core
Copy the code

4. Common commands

Update gem: sudo gem update --system Gem sources --remove [https://ruby.taobao.org/](https://ruby.taobao.org/) 3. Modify the gem source: gem sources-a[https://gems.ruby-china.org](https://gems.ruby-china.org/) 4. Check whether the gem source is the latest gem source-lUpdate cocoapods sudo gem install cocoapods -v'Version number'Sudo gem install -n /usr/local/bin cocoapods --pre 7. View the upgraded cocoapods version: pod --versionCopy the code

5. Use summary

  • Step 1: Create the project.
  • Step 2: Create a Podfile.
  • Step 3: Fill in the third-party library information to your podfile and save it.
  • Step 4: Install the third-party library, exit, and open it with the xcworkspace file. This step is very important and can only be opened with this file, not the previous XcodeProj file, otherwise it will prompt the third-party library can not be found.
  • Step 5, import the header file and start using it.

6. Frequently asked Questions

Problem a:

[!]  Oh no, an error occurred. It appears to have originated from your Podfile at line 1. Searchforexisting github issues similar to yours: https://github.com/CocoaPods/CocoaPods/search?q=%2FUsers%2Fhuaqiao%2FDesktop%2FUserCommand1%2FPodfile%3A1%3A+syntax+erro r%2C+unexpected+%27%3A%27%2C+expecting+end-of-input%0Aplatform+%3A+ios+%0A++++++++++%5E&type=Issues

If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new

Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
Copy the code

You need Scandisk Cocoapods: So

sudo gem uninstall cocoapods
sudo gem install cocoapods
pod setup
Copy the code

Problem two:

Invalid `Podfile` file: [!]  Unsupported options `{:exclusive=>true} `for target 'CocoaPodsDemo'
Copy the code

This is usually pod install other projects, the solution is to:

target 'mySuperApp_Tests', :exclusive => true do 
pod 'mySuperApp', :path => '.. / 'end
Copy the code

To:

target 'mySuperApp_Tests' do pod 'mySuperApp', :path => '.. / ' end
Copy the code

Question 3:

[!]  Unable to add asource with url 
`https://github.com/CocoaPods/Specs.git` named `master`.
Copy the code

Solutions:

cd ~/.cocoapods/repos 
git clone https://github.com/CocoaPods/Specs.git master
Copy the code

Another error is:

[!]  Unable to add asource with url `https://github.com/CocoaPods/Specs.git` named `master-1`.
You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.
Copy the code

Solutions:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Copy the code

It can be done through:

cd ~/.cocoapods
du -sh *
Copy the code

Command to view file sizes

If pod install > < span style = “box-sizing: box-sizing; color: RGB (50, 50, 50); line-height: 20px; white-space: inherit! Important;” The command to add parameters is as follows:

pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
Copy the code

Problem five: Prompt can not find the end of the file

1, find TARGETS -> Build Settings -> SearchPaths -> User Header SearchPaths double click 2 in the blank, click ‘+’, add a new key ${SRCROOT}, Set the value to recursive

Q6: Pod install and pod update: One to install and one to update.

Podfile.lock: This file is used to save the installed version of the Pods-dependent library. Pods folder: Full of reference tripartite libraries. If the podfile. lock file is lost and you use pod Install, and your Podfile contains libraries of no specified version, your library will download the latest version. Some of the more active third party projects update so frequently that when they update the method name or implementation, the code you are calling will report an error. This is disastrous. A special note: Using pod update updates your Podfile.lock files to the latest version, and any time they update the method name or implementation, your code will report an error, so don’t cripple. So remember to always use Pod Install for your own project or for someone else’s source code. For POD Update, see if you need to update the library three times. (I still recommend specifying the version in your Podfile, and simply change the version number in your Podfile to upgrade. Then pod install.

Question 7:

sudo gem sources -a https://ruby.taobao.org/ 
Error fetching https://ruby.taobao.org/:
	server did not returnA valid file (http://ruby.taobao.org/specs.4.8.gz)Copy the code

This is really foolproof ah, the Internet to find a long time to solve the solution, tried HTTPS to HTTP, also tried:

1. rvm pkg install openssl
2. rvm reinstall all --force
Copy the code

and

$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l*** CURRENT SOURCES ***
Copy the code

Finally ask group friend, group friend say have a try, can open this website, the result is the company network authority problem, to some treasure cannot visit normally, / gas cry/gas cry.

Question 8:

Error while running sudo gem install cocoapods:

ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/fuzzy_match - /usr/bin/xcodeProjCopy the code

Can be:

sudo gem install -n /usr/local/bin cocoapods
Copy the code

“Reference”

  • Install Cocoapods in Mac OS X 10.11.1
  • Install and use CocoaPods and faQs