iOS- use third-party management CocoaPods

iOS- use third-party management CocoaPods

1. About CocoaPods
we will definitely use in the development process, many third-party libraries, these libraries or frameworks may also depend on other libraries and frameworks, import manually every time, but also pay attention to the version compatibility, sometimes you need to configure the environment variables, it is trouble, there may be wrong compilation fails, it is disgusting.
But there is no way to Han, the great God who perhaps are their own package libraries and frameworks, but for me this side dish, or need to use a lot of third-party developers to increase my efficiency.
Fortunately, the project has CocoaPods do rely tool.

2. Install CocoaPods

Step one: Open a terminal.
The second step: the implementation of instruction: $ sudo gem install cocoapods
third step: After a successful operation command, execute command: $ pod setup

This is actually on it, waiting for download from GitHub repository CocoaPods of it.
Before using Taobao mirror, due later Taobao is not maintained, the staff can not be used to switch https://gems.ruby-china.com

In other source instruction:
$ the sudo GEM Source --remove https://rubygems.org/
$ the sudo GEM Source -a https://gems.ruby-china.com

3. Use the search base CocoaPods
this two ways about it, go on a search site, and the other end is then directly execute the command search.

The first is: Search Site
URL: https://cocoapods.org/
search interface

Copy the contents of the prompt box directly to the project in the Podfile file on it.

The second: terminal search
execution command: $ pod search AFNetworking
then put the following things to be written Podfile version and show out.

4. Use CocoaPods
use the Internet is through their new terminal or a Podfile out in the project, and then write in the format, then install, I used to let the system create it.

Step one: Open Terminal
Step two: executing instructions: $ cd project directory of your project
here is the project directory where .xcodeproj * files are located directly find here in the folder, and then put the file on a folder directly drag the end, the path himself came out.
The third step: execute command: $ pod init
instruction is executed successfully, Podfile automatically generates a text file that can be opened directly edit.

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'Test' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for Test
  pod 'AFNetworking', '~> 3.0.4'

end

Re-do and places to write third party between the end of the name and version number you want to import it, here's Objective-C, so the situation on the static link library used.
Step four: Perform command: $ pod install
it.

5. Add a new dependent libraries
Step 1: Execute command: $ pod setup
used to update the look of the first
Step two: Open Podfile file, modify the content to do between the end, save.
The third step: execute command: $ pod install
and it.

6. Other
1. After using CocoaPods remember later open the project you want to open the file * xcworkspace white.
2. If the project can not find time to import the header file, then need to set the path
to select the project Target -> Build Settings -> Search header, find the "User Header Search Paths" -> add a value of "$ (PODS_ROOT)", and select "recursive", so Xcode will recursively search for files in the project directory and will automatically find Pods files, header files automatically filled so that the function will be OK.

7. questions about the install and update the pod
For starters, install or use the pod and pod update will not affect the overall situation, so some people got used to it has been used to update his way. Here's a brief update about the difference between these two methods.

(1) pod install:
This is the first time pods when used inside the project, and also every time you edit your Podfile (add, remove, update) when using.

Every time you run the command pod install, download, install new library, it would also put your installed version of each library are written in a Podfile.lock file inside. This file Record your version number of each installed library, and lock these versions.

When you use the pod install it only solves the pods inside, but the dependencies between those libraries are not Podfile.lock file inside. For those inside the library Podfile.lock listed, which will download in Podfile.lock explicit version, and will not go to the library to check if a new version.

(2) pod outdated:
When you run the pod outdated command, CocoaPods will list all those libraries have a new version of the more Podfile.lock inside (the current versions of those libraries are installed with the). This means that, if you run pod update PODNAME, if there is a new version of the library, and the new version is still comply with the limits in Podfile where it will be updated.

(3) pod update:
When you run pod update PODNAME command, CocoaPods will help you update to a new version of the library, without the need to consider Podfile.lock inside the limit, it will be updated to the new version of the library as much as possible, Meet the release restrictions Podfile inside.

If you run pod update, not followed by the name of the library, CocoaPods will be updated every Podfile inside the library to the latest version as possible.

(4) Summary:
You should use the pod update PODNAME to update only a specific library (check if a new version and update to the new version as much as possible). Correspondence, you should use the pod install, this command does not update those libraries already installed.

When you add a library in your Podfile inside, you should use the pod install, rather than pod update, then it will install the library, you do not need to update other installed libraries.

You should use the pod update to update a particular library or all libraries (limit Podfile's).

At the same time, remember that when you submit the code commit to a remote warehouse, take Podfile.lock file.

8. Update Ruby
sometimes use problem occurs '' pod install '' time.

-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory

Quite simply, we update at Ruby environment just fine.
Open a terminal, then:
(1) view the current version of Ruby.

ruby -v

(2) update Ruby.

Sources --remove GEM https://rubygems.org/
GEM Sources -a https://ruby.taobao.org/ (mirroring the Ruby point taobao, to avoid the wall, you know)
GEM Sources the -l (used to check use Alternatively mirror location successful)

(3) to download and install CocoaPods.

sudo gem install cocoapods

Published 83 original articles · won praise 12 · views 180 000 +

Guess you like

Origin blog.csdn.net/shengdaVolleyball/article/details/83783683