CocoaPods is a dependency management tool for iOS projects that allows developers to quickly integrate third-party open source libraries and add dependency libraries. As Ruby, Gem, Mac OSX, Xcode, and CocoaPods update, the installation method of CocoaPods changes as well, and of course there are all kinds of problems.

Tools: Mac OSX OPERATING system: OSX 10.12.2 Compiling environment: Xcode 8.2.1 Mac terminal

1. Open your Mac Terminal ** and search for terminals in the upper right corner or go to the “Other” software folder on The Launchpad and go to Terminals.

2. Update Ruby to replace the default source of Ruby, remove https://rubygems.org/, and add the HTTPS source of Taobao (point the Ruby image to Taobao to avoid being blocked).

gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/ 
Copy the code
Gem sources --remove http://ruby.taobao.org/ PS: Taobao was HTTP before, now to replace with HTTPS.Copy the code

3. Verify that the default Ruby source was successfully replaced

 gem sources -l
Copy the code

4. Update the Mac Gem, the standard package for managing Ruby libraries and programs

Sudo gem update --system or sudo gem update -n /usr/local/ bin - systemCopy the code

Then enter the administrator password (if you can’t see the input result, enter the password directly after entering)

5. Install CocoaPods

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

Add the CocoaPods management library to your iOS project (use) 1. Create a new project ZLPodTest

2. Enter CD + space on the terminal and drag the project folder to the terminal. The path is automatically generated.

3. Create and edit a Podfile (configuration file). Enter vim Podfile or POD init (recommended) to edit a file. Enter I on the keyboard to enter the editing mode and enter the following content:

platform :ios, '8.0'Target Target Namedo
pod 'AFNetworking'.'~ > 3.1.0'
end
Copy the code

Press Esc to exit editing, then press Shift + colon, and enter wq to exit editing.

4. Import third-party library and related dependent library for project terminal input:

pod install
Copy the code

Then wait patiently to download the third-party library. If the file is large, it may take a long time. After a little waiting, the terminal will print the progress.

Instead of clicking on zlpodtest.xodeproj to open the project, click on ZLpodtest.xcworkspace

Open the project and see the project structure and test it:

If you need to import CocoaPods from multiple third parties at the same time, you need to import CocoaPods from multiple third parties at the same time. To do this, you need to modify the Podfile, which you edited with Vim and saved in the root directory of your project. After you have manually modified the Podfile, you need to run the pod install command again. Such as:

platform :ios
target 'ZLPodTest' do
pod 'MBProgressHUD'.'~ > 0.9.2'
pod 'MJRefresh'.'~ > 3.1.0'
end
Copy the code

### Remove CocoaPods

  1. Edit the Podfile, clear it of all libraries, and type pod Install. The third-party libraries and associated dependent libraries are emptied.
  2. Delete the previous four files, Podfile, Podfile.lock, Pods folder, and.xcworkspace file.
  3. Then open.xcodeProj and remove the libPods. a and Pods.xcconfig references from the project.

TARGETS – Build Phases remove the Pods option, and the drop is complete.

1. If we download the project demo(using pod management) to learn, directly run the error as follows:

diff: /.. /Podfile.lock: No such file or directory diff: /Manifest.lock: No such file or directory error: The sandbox is notin sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
Copy the code

Solution: In the terminal input CD + space drag into the project you need, that is to say, use terminal switch to the project directory, and then re-enter the terminal: pod Install restart the project, clean + build project, running miracle yo!

2. This problem occurs when using cocoapod to import a Swift third party:

[!]  Pods writteninSwift can only be integrated as frameworks; add `use_frameworks! ` to your Podfile or target to opt into using it.Copy the code

Installation OC configuration method:

platform :ios, '8.0'
pod 'Alamofire'.'~ > 4.3.0'
end
Copy the code

Apple does not allow static libraries to be built that include Swift, unlike OC, which can use language versions of platform versions.

Solution: For problems like Swift, add a handler like use_frameworks!

platform :ios, '8.0'
pod 'Alamofire'.'~ > 4.3.0'
use_frameworks!
end
Copy the code

3. If other problems occur, update ~