CocoaPods private warehouse creation (ultra detailed)

This article is published in BY Blog, Jane reprint please keep an article on the link “CocoaPods public warehouse creation”

Preface

The recent reference to a large number of online CocoaPods private warehouse tutorial, according to the tutorial to get the pod warehouse is such a ~

CocoaPods private warehouse creation (ultra detailed)

The code and the version are mixed up, it’s just too bad

Although it can be used, but the CocoaPods itself and the structural design is not consistent.

In the last article, “the creation of the CocoaPods public warehouse,” we learned that the master directory only stored in the description of the code library, rather than storing the code. Like this

CocoaPods private warehouse creation (ultra detailed)

The code is stored in the repository

CocoaPods private warehouse creation (ultra detailed)

A lot of people do not understand the work principle of CocoaPods copy and paste someone else’s tutorial to do tutorial

Tucao end, enter the text

text

Create version Library (repo)

First, create a master like version of the GIT description file storage warehouse, because it is a private git warehouse, we choose oschina to create a remote private warehouse (for free) or they can be created in the GitHub ($7/month).

Take oschina as an example

Create repository

CocoaPods private warehouse creation (ultra detailed)

Back to the terminal, adding the remote private version repository to the local, repo is the abbreviation of the repository repository.

$pod repo MyRepo add https://git.oschina.net/baiyingqiu/MyRepo.git

View in the Finder directory ~/.cocoapods/repos, can be found to add a MyRepo repository

CocoaPods private warehouse creation (ultra detailed)

Create code library

Back to oschina to create a private library

Add MIT License and README when creating

CocoaPods private warehouse creation (ultra detailed)

The warehouse is cloned to the local, add your code files, warehouse name.Podspec description file, and.Swift-version.

as follows

CocoaPods private warehouse creation (ultra detailed)

.swift-version file used to know swift version, with the command line to create

$echo "3" >.Swift-version

.podspec file is your pod description of the code library, you can create a blank template through the pod command:

$pod spec create MyAdditions

Or it is strongly recommended that you copy the following template directly

Pod:: Spec.new do |s| s.name = "MyAdditions" # project: s.version = "0.0.1" # version and your warehouse tag number corresponding to s.license = "MIT" # open source certificate s.summary = "private pod code" # project s.homepage = "https://git.oschina.net/ baiyingqiu/MyAdditions" # warehouse homepage s.source = {=>: git; "https://git.oschina.net/baiyingqiu/MyAdditions.git, tag: =>" #{s.version} "}# your warehouse address with the SSH address, s.source_files =" MyAdditions/*.{h, m} "# your code position, BYPhoneNumTF/*.{h,.H and m} said BYPhoneNumTF folder.M file s.requires_arc = true # all ARC enabled: s.platform = IOS," 7 "and # platform support the minimum version of s.framew # Orks = "UIKit", "Foundation" # support framework # s.dependency = "AFNetworking" User s.author = # dependent libraries # {"BY" => "[email protected]";} # author s.social_media_url = "http://qiubaiying.github.io" # personal homepage end

Here I would like to talk about a pit, with the oschina to create a private warehouse, in the verification may not find the MIT LICENSE certificate, the

S.license = "MIT" modified to specify file s.license = {type => "MIT", "file", "LICENSE"}

Then start to verify that our warehouse is configured correctly and modify it as required

$pod lib lint

General error warning, need to add –private or –allow-warnings, you can verify

$pod lib lint --private

After successful verification

-> MyAdditions (0.0.1) MyAdditions passed validation.

Push the description file to the repository

Label the project to the remote warehouse, the label number and version number corresponding to 0.0.1

Finally, we describe the description of our code repository, push, into our repository

$pod repo MyRepo push MyAdditions.podspec

At this time, the remote warehouse will be verified, the success will be found in the ~/.cocoapods/repos/MyRep new warehouse description information

CocoaPods private warehouse creation (ultra detailed)

If there is an error message

[repo] The `MyRepo` `../.cocoapods/repos/MyRepo` is not at clean

Update our repository,

$pod repo update MyRepo

Then continue to upload.

Pod repo push MyAdditions.podspec is the process of MyRepo

  1. Verify MyAdditions.podspec file
  2. Pull remote version library MyRepo
  3. Add MyAdditions.podspec to the repository
  4. Push to remote

After the completion of the search we can search in pod

$pod search MyAdditions

-> MyAdditions (0.0.1) Some category of the framework and UIKit pod'MyAdditions','~> 0.0.1' - Homepage: https://git.oschina.net/baiyingqiu/MyAdditions - Source:; https://git.oschina.net/baiyingqiu/MyAdditions.git - Versions: 0.0.1 [MyRepo repo] (END)

Use of private pod Libraries

The use of private pod libraries need to add this sentence in Podflie, indicating that your repository address.

Source 'https://git.oschina.net/baiyingqiu/MyRepo.git'

Note that the address of the repository, rather than the address of the code base

If there is also the use of a public pod library, you need to bring the public library address

Source 'https://github.com/CocoaPods/Specs.git'

The final Podflie file becomes this way

Source 'https://github.com/CocoaPods/Specs.git' source 'https://git.oschina.net/baiyingqiu/MyRepo.git' platform: IOS,'8.0'target do "MyPodTest" use_frameworks! Pod "BYPhoneNumTF" pod "MyAdditions" # public library # our private library pod "BYAdditions" # this is me and added to the repository in another code library end

Test:

$pod install

When loading is complete, you can see that the code has been integrated into our project

Perfect!

CocoaPods private warehouse creation (ultra detailed)

Back to the Fender in ~/.cocoapods/repos, you will find that repos has added a pod version of the library.

CocoaPods private warehouse creation (ultra detailed)

When executing the pod install command

  • Will pull the remote Podflie source tag library to the local repos folder
  • Search our pod ‘MyAdditions’ MyAdditions.podspec file in the repository.
  • According to the source address described in the MyAdditions.podspec file to download and integrate into the project

epilogue

Through the creation of CocoaPods private warehouse and the creation of CocoaPods public warehouse, these two articles, I believe we have a deeper understanding of the working principle of CocoaPods.

In the process of blogging and creating, on a lot of pit (left the previous tutorial), a lot of things only you can really understand the operation end.

Finally, if there is any error in this article or what is the different point of view welcome to exchange. ?