Summary:
The Podfile file reads the. podspec file first, and downloads the third-party library into the project, based on the. podspec file's point.
This article first through one or two or three items, these three steps explain how to create a . podspec file in the Local. Cocoapod Library, third-party libraries in the remote machine example.
The fourth item in this article explains the . podspec file in the local project, the third-party library in the remote machine 's setup method; finally , the. podspec file is also set in the local project, and the third-party library is in the native project.
The text explains:
First, create a third-party library that requires pod management
(1) Create a third-party library locally named Lvpodlibrary, with the command created as follows:
[Email protected] : pod Lib create lvpodlibrary //input command
Answer four questions according to the prompts, 1. Whether an example project is required; 2. Select a test framework; 3. Whether the prefix is based on the view test; 4. Class.
Join the class we want to manage with pod, which is named LvPodLibrary.h and LVPODLIBRARY.M.
The post-join directory structure is as follows:
(2) Create a new repository on GitHub, the remote Lvpodlibrary library. Get the address, like mine is https://github.com/SheronLv/lvPodLibrary.git. Push the local library created above to the remote:
[Email protected]:~/codelv/github/git Add. [Email protected]:git commit-m "Initial commit of Library"onbranch masternothing to commit, W Orking directory Clean[email protected]://Add remote repository //Submit to remote repository
Because a third-party library is available in the Podspec file lvpodlibrary this git version-controlled project also requires tag numbers, so we're going to hit a tag
git tag-m "first release" "0.1.0 " [email protected]: git push--tags //push tag to remote repository
That is, I am now pushing the lvpodlibrary third-party library is version 0.1.0.
(3) Edit the Lvpodlibrary.podspec file, or if the library was created in another way without this file, create a Lvpodlibrary.podspec file
[Email protected]:~/codelv/github/lvpodlibrary$ pod Spec Create lvpodlibrary https://github.com/SheronLv/ Lvpodlibrary.git
The contents are as follows:
Pod::spec.new do |s| s.name = "Lvpodlibrary" #名称 s.version = "0.1.0" s.summary = "Just testing" #简短介绍, here is a detailed introduction to s.description = <<-DESC
Testing testing Testing DESC s.homepage = "Https://github.com/SheronLv/lvPodLibrary" s.license = ' MIT ' s.author = {"Sheron lv" = "[email protected]" } s.platform =: iOS, "7.0" S.source = {: git = "h Ttps://github.com/sheronlv/lvpodlibrary.git ",: Tag = s.version } s.source_files =" Lvpodlibrary "," lvpodlibrary/**/*. {h,m} "end
Verify that the. podspec file is available
[Email protected]:~/codelv/github/-lvpodlibrary (0.1. 0//This prompt indicates that the message is available
Then push all the files to the far end.
Ii. Creation of Podspec Warehouse
(1) Create new repository on GitHub as a remote repository for Podspec, for example, I created a warehouse called Lvpodspec on GitHub.
(3) Add the remote Podspec repository to the local repository directory, which is the ~/.cocoapods/repos directory.
[email protected]:~$ pod repo add lvpodspec https://github.com/SheronLv/lvPodSpec.git //input command
Cloning spec repo ' lvpodspec ' from ' https://github.com/SheronLv/lvPodSpec.git ' //execution process, results
At this point, the local ~/.cocoapods/repos directory already has a warehouse named Lvpodspec. The pod Search command allows you to find information about this library:
Pod Search Lvpodlibrary
Find the following information
Lvpodlibrary (0.1.0)
Just Testing
Pod ' lvpodlibrary ', ' ~> 0.1.0 '
-Homepage:https://github.com/sheronlv/lvpodlibrary
-Source:https://github.com/sheronlv/lvpodlibrary.git
-versions:0.1.0 [Lvpodspec repo]
Copy the previous Lvpodlibrary.podspec file to the local Lvpodspec project with the following directory levels:
Then push all the content to the remote Lvpodspec. (In fact, you can delete the Lvpodlibrary project under the Lvpodlibrary.podspec file, does not point to it.) But now you can keep it, and then practice the. podspec file that directly points to the third-party library can be used)
(Note: Each update version of the tag, the name of the parent directory is also updated, or to create a new folder such as 0.1.1, 0.1.2, otherwise cannot find this version of. Podspec)
Iii. using Pods to manage third-party libraries in new projects
Create a new demo project with the following directory levels
The podfile of this project are as follows:
SOURCE ' https://github.com/SheronLv/lvPodSpec.git ' //NOTE: If you do not add a source sentence, you may not find it, you will get an error.
Platform:ios,"7.0"inhibit_all_warnings! "lvdemo" do' lvpodlibrary ','0.1.0'end
Run the pod install and the project will have a lvpodlibrary project in which to use it, at the following directory level:
Summary: After many practices, the above three steps, in fact, are the following points to the relationship:
(1) Podfile in a project that needs to use a third-party library points to a. podspec file in a local warehouse
For example, the key code in Podfile
Pod ' lvpodlibrary ', ' 0.1.5 '
( 2) address of the local. Podspec file to the third-party library of the remote repository
For example, the Lvpodlibrary.podspec file for ~/.cocoapods/repos/project Lvpodspec in the local warehouse
S.name = "Lvpodlibrary"
S.version = "0.1.5"
S.source = {: git = "Https://github.com/SheronLv/lvPodLibrary.git",: Tag = s.version}
S.source_files = "Lvpodlibrary"
(3) Remote Warehouse Lvpodlibrary.git
The key is:
To hit the tag when push;
The directory structure that holds the third-party library lvpodlibrary is consistent with the s.source_files specified in the. podspec file.
Use a graph to indicate:
We know that when you run the pod install, you are running Local. Cocoapods. Podspec, remote corresponding. Podspec and the. Podspec created in the third library you want to manage is not working.
Four, Ps:podfile different wording
(1)
' lvpodlibrary ' ,: git ='https://github.com/SheronLv/lvPodLibrary.git ' 0.1.2 '
In this way, the pod will go to the remote Git address, tag is 0.1.2 in the submitted code of the Lvpodlibrary.podspec file, according to lvpodlibrary.podspec file download the corresponding third-party library.
(2) Copy the Lvpodlibrary.podspec file created above to the project directory that needs to depend on the library code, such as this project Demo/spec/lvpodlibrary.podspec, and then modify the dependency of the library in Podfile as:
' lvpodlibrary ' ' ./spec/lvpodlibrary.podspec '
Executing pod install also pulls the code to the corresponding third-party library.
(3) If the code of the third-party library does not want to be lvpodlibrary, you can add the code to the pod by using path, as follows :
#Podfile中这样写 ' lvpodlibrary ' ' ./localpod/lvpodlibrary.podspec ' This is written in the #.podspec file s.source = {: Tag = s.version}s.source_files "lvpodlibrary"
Note: When this is written, the file Lvpodlibrary.podspec and the third-party library code Lvpodlibrary are placed in the same folder of this project, for example, this item is the Localpod folder, otherwise the third-party library cannot be found.
The file directory is as follows:
Create PODSPEC, use pods to manage third-party libraries