Cocoapod is a powerful third-party open source framework of management tools, in which a variety of open source libraries, many of which are continuously updated, we can use in the use of the latest class library, as we use the open source framework, we will inevitably encounter the third-party class library may appear bug, Or because of Apple's SDK update, the various frameworks need to be updated, using Cocoapods can be a button to update to the latest open source framework!
The first is to install Cocoapos, it needs a ruby environment, but the newer Mac system has already installed Ruby for us, so we can now install Cocoapods directly!
To install Cocoapods steps:
1. Open the terminal and set the root password
Execute the following command to set the root password (if you have not set the root password)
sudo passwd root
New Password:retype New Password:
Enter your password and confirm
2. Installing Cocoapods
(1) Execute the order:
Su
Enter password to switch to root user
(2) Execution:
Gem Sources--remove https://rubygems.org/
Wait for a response (output
Https://rubygems.org/removed from sources
)
(3) then execute:
Gem Sources-a http://ruby.taobao.org/
(Output is
http://ruby.taobao.org/added to sources
)
(4) To see if it is associated to the mirror, perform
Gem Sources-l
(Output
Current SOURCES * * *
http://ruby.taobao.org/
, which represents the successful execution of the previous command)
(5) Install Cocoapods, perform
sudo gem install Cocoapods
It may take a few minutes for the Cocoapods library to be installed and the output is as follows:
Fetching:i18n-0.7.0.gem (100%) successfully installed I18n-0.7.0fetching:thread_safe-0.3.5.gem (100%) Successfully Installed Thread_safe-0.3.5fetching:tzinfo-1.2.2.gem (100%) successfully installed tzinfo-1.2.2Fetching: Minitest-5.5.1.gem (100%) successfully installed Minitest-5.5.1fetching:activesupport-4.2.1.gem (100%) Successfully Installed Activesupport-4.2.1fetching:nap-0.8.0.gem (100%) successfully installed Nap-0.8.0fetching:fuzzy_ Match-2.0.4.gem (100%) successfully installed Fuzzy_match-2.0.4fetching:cocoapods-core-0.36.0.gem (100%) Successfully installed Cocoapods-core-0.36.0fetching:claide-0.8.1.gem (100%) successfully installed Claide-0.8.1fetching:colored-1.2.gem (100%) successfully installed Colored-1.2fetching:xcodeproj-0.23.0.gem (100%) Successfully installed Xcodeproj-0.23.0fetching:cocoapods-downloader-0.8.1.gem (100%) Successfully installed Cocoapods-downloader-0.8.1fetching:cocoapods-plugins-0.4.1.gem (100%) successfully installed Cocoapods-plugins-0.4.1fetching:cocoApods-try-0.4.3.gem (100%) successfully installed Cocoapods-try-0.4.3fetching:netrc-0.7.8.gem (100%) Successfully Installed Netrc-0.7.8fetching:cocoapods-trunk-0.6.0.gem (100%) successfully installed Cocoapods-trunk-0.6.0Fetching : Molinillo-0.2.1.gem (100%) successfully installed Molinillo-0.2.1fetching:escape-0.0.4.gem (100%) Successfully Installed Escape-0.0.4fetching:open4-1.3.4.gem (100%) successfully installed open4-1.3.4fetching: Cocoapods-0.36.0.gem (100%) successfully installed cocoapods-0.36.0parsing documentation for i18n-0.7.0Installing RI documentation for i18n-0.7.0parsing documentation for thread_safe-0.3.5installing RI documentation for THREAD_ safe-0.3.5parsing documentation for tzinfo-1.2.2installing RI documentation for tzinfo-1.2.2parsing documentation for Minitest-5.5.1installing RI documentation for minitest-5.5.1parsing documentation-Activesupport-4.2.1unable to Convert "\x84" from Ascii-8bit to UTF-8 for Lib/active_support/values/unicode_tables.dat, SkippinginstaLling RI documentation for activesupport-4.2.1parsing documentation for nap-0.8.0installing RI documentation for nap-0.8. 0Parsing documentation for fuzzy_match-2.0.4installing RIS documentation for fuzzy_match-2.0.4parsing documentation for Cocoapods-core-0.36.0installing RI documentation for cocoapods-core-0.36.0parsing documentation for Claide-0.8.1installing RI documentation for claide-0.8.1parsing documentation for Colored-1.2installing RI documentation for colored-1.2parsing documentation for xcodeproj-0.23.0installing RI documentation for xcodeproj-0.23.0parsing documentation for cocoapods-downloader-0.8.1installing RI documentation for cocoapods-downloader-0.8.1parsing documentation for cocoapods-plugins-0.4.1installing RI documentation for cocoapods-plugins-0.4.1parsing documentation for cocoapods-try-0.4.3installing RI documentation for cocoapods-try-0.4.3parsing documentation for netrc-0.7.8installing RI documentation for netrc-0.7.8parsing Documentation for COCOAPODS-TRUNK-0.6.0Installing RI documentation for cocoapods-trunk-0.6.0parsing documentation for Molinillo-0.2.1installing RI documentation for molinillo-0.2.1parsing documentation for escape-0.0.4installing RI documentation for escape-0.0.4parsing documentation for open4-1.3.4installing RI documentation for open4-1.3.4parsing documentation for Cocoapods-0.36.0installing RI documentation for COCOAPODS-0.36.020 Gems installed
(6) Test pod command, execute at terminal
Exit
Quit root because cocoapods is not allowed to work properly on root by default
Pod
Will output:
sh-3.2# exitexitmacios:~ mac$ podusage: $ pod COMMAND CocoaPods, the Cocoa Library package Manager. Commands: + init Generate a podfile for the current directory. + Install install project dependencies to Podfile.lock versions + IPC inter-process communication + Lib Develop pods + List List pods + outdated show outdated project Dependencies + plugins show Availa ble CocoaPods plugins + repo Manage spec-repositories + search searches for pods + setup CocoaPods environment + Spec Manage pod specs + trunk Interact with the CocoaPods API (e.g. publishing n EW specs) + Try try a pod! + Update update outdated project dependencies and create new podfile.lockoptions:--silent Show Nothing--version show the version of the tool--verbose show more debugging information--no-ansi Show Output without ANSI codes--help ShoW help Banner of specified commandmacios:~ mac$
Output as above, code Cocoapods installed successfully!
3. Using Cocoapods
Start a new iOS project such as Firstapp, and then close the project [this point is important, otherwise it will not work properly using Cocoapods installation class Library], switch to the project's root directory (drag the project folder can quickly switch)
(1) Implementation
Cd/users/mac/desktop/firstapp (your project root directory path)
(2) Implementation
Pod Init
After execution completes, a file is created under the root directory: Podfile
(3) Search for the class library you need, just enter a partial string, automatically find
For example, let's search the Afnetworking class library and execute:
Pod Search Afnet
If this is the first time to use the Cocoapods search will be full of some, wait a moment, you can see a lot of AF related content came out, which have we want to afnetworking framework
Some of the output is as follows:
Afnetworkactivitylumberjacklogger (2.0.3) afnetworking 2.0 Extension for Network Request Logging with support of Cocoalumberjack forked from Afnetworkactivitylogger by Matt Thompson pod ' afnetworkactivitylumberjacklogger ', ' ~> 2. 0.3 '-homepage:https://github.com/sohayb/afnetworkactivitylogger-source:https://github.com/sohayb/afnetworkacti vitylogger.git-versions:2.0.3 [Master repo]-> afnetworking (2.5.1) A delightful IOS and OS X networking Framewor K. Pod ' afnetworking ', ' ~> 2.5.1 '-homepage:https://github.com/afnetworking/afnetworking-source:https://gi thub.com/afnetworking/afnetworking.git-versions:2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2. 1, 2.2.0, 2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-rc2, 2.0.0-rc1, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0rc2, 1.0rc1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
Copy out the commands we need to use:
Pod ' afnetworking ', ' ~> 2.5.1 '
This command represents the version of the installation AF, which is 2.5.1
How AF is installed into the project:
Open the Podfile file in the project root directory, and write the above command to install AF, if you have more than one frame branch written to it
# Uncomment this line to define a global platform for your project# Platform:ios, ' 6.0 ' target ' Firstapp ' Dopod ' afnetwork ing ', ' ~> 2.5.1 ' endtarget ' firstapptests ' doend
As above, put pod ' afnetworking ', ' ~>2.5.1 ' after do, you can
If there are other frameworks, place them in the
Pod ' afnetworking ', ' ~>2.5.1 ' on the next line, you can
Execute commands to install AF or other frame commands that you write in Podfile:
Pod Install
Wait a few two minutes for the installation to succeed,
The output is as follows:
Macios:firstapp mac$ pod installanalyzing dependenciesdownloading dependenciesinstalling AFNetworking (2.5.1) Generating Pods projectintegrating client project[!] Please close any current Xcode sessions and use ' Firstapp.xcworkspace ' for this project from now on.
Then we installed successfully, according to his output of the prompt, the next time you use the Firstapp.xcworkspace can be opened ()
{Do not open the original firstapp.xcodeproj file, will be error}
4. Using frames, use <> angle brackets to introduce
To use AF to import the following frames!
#import <AFNetworking.h>
Original address: Http://blog.csdn.net/yangbingbinga
Next section: How to troubleshoot problems with using Cocoapods
iOS Development Open Source Framework management tool Cocoapods installation use