Create a private index library from the pocket CocoaPods

Preface

What is an index library? Why do you want to create a private index library? The terminal inputs pod repo, and if the previous configuration has not been configured, the output information is:

Master - Type: git (Master) - URL: https://github.com/CocoaPods/Specs.git - Path: /Users/Jack/.cocoapods/repos/master

Open the https://github.com/CocoaPods/Specs browser, you can see a Specs folder, the folder contains all the support framework of CocoaPods index, but the https://github.com/CocoaPods/Specs.git is open the index, you can only add open (open) framework, if want to let private frame support CocoaPods, this time must use the private library.

text

If the private frame already exists, simply go to the local project root directory, create podspec, upload the correct information, upload the push file, and then podspec the file to the private index library.

Pod spec create [podspec podspec pod to create the file name] lib lint //podspec / pod spec lint //podspec local authentication verification git add. Git commit remote -m XX git push origin master pod repo push [private] [podspec index database file] / / podspec file push to private library

If you create a private framework from scratch, you can follow the following steps:

(take TestLib as an example, please replace it yourself)

The terminal goes into the folder ready to create lib, and executes the command

Pod lib create TestLib

This process may take a few seconds, and then the following information will appear:

What language do you want to use?? [Swift / ObjC] Would you like to include a demo application with your library [Yes / No]? Which testing frameworks will you use? [Specta / Kiwi / None Would you like to do] view based testing [Yes / No]?

According to the prompt input, after completion, will automatically open the corresponding TestLib Example project

Execute the tree command to view the directory structure

01:TestLib Jack$tree TestLib -L TestLib Example, had just 2 Podfile, Podfile.lock Pods, had just had, TestLib, TestLib.xcodeproj, TestLib.xcworkspace had just, Tests - LICENSE - README.md had just had - TestLib / Assets / Classes / Song - - TestLib.podspec - _Pods.xcodeproj -> had; Example/Pods/Pods.xcodeproj 10 directories, 5 files

Put components into TestLib/Classes and delete ReplaceMe.m, enter Example folder, execute pod install, TestLib corresponding Example project has been loaded, and can carry on demo demonstration. Later, every time you update lib, you need to go into Example and execute pod install to get the latest code

Create a private index library from the pocket CocoaPods
TestLib/Classes
  • Creating a remote private library

Since GitHub creates a private library, you need to pay for it. Here’s a demo with coding

Create a private index library from the pocket CocoaPods
remote private library

Here, README.md open source license, gitignore does not need to add the directory structure of TestLib from above can see, pod lib create has created the three files, if added, when commit may lead to a conflict (the contents of the file are not identical), so as to create a clean private library.

  • Modify the podspec file
Pod:: Spec.new do |s| s.name ='TestLib's.version ='0.1.0' s.summary ='TestLib's.description = < < -DESC TestLib is a demonstration of DESC ='https://coding.net/u/coder_01/p/TestLib' s.screenshots s.homepage # ='www.example.com/screenshots_1','www.example.com/screenshots_2' = {s.license: type =>'MIT', file: =>'LICENSE' s.author = {'01_Jack'}} {s.source = =>'123@qq.com': Git =>'git@git.coding.net:coder_01/PrivateSpecs.git', tag: => s.version.to_s} # s.social_media_url ='https://twitter.com/< TWITTER_USERNAME> ='8.0'; s.source_files ='TestLib/Classes/**/* 's.ios.deployment_target '# s.resource_bundles = {'TestLib' =>} # #; ['TestLib/Assets/*.png'] s.public_header_files ='Pod/Classes/**/*.h's.frameworks ='UIKit''MapKit'# #, s.dependency'AFNetworking','~> 2.3'end
  • Local authentication of podspec:
Pod lib lint --private

If Waring validation does not pass, you can add –allow-warnings, remote authentication, and pod repo push

  • Pack

After verification, packaged class library, here you can use cocoapods plug-in cocoapods-packager to complete (manual packaging too troublesome). If you do not have cocoapods-packager installed before, execute the following command:

Sudo gem install cocoapods-packager

Packļ¼š

Pod package TestLib.podspec --force

The default package is.Framework, and if added to the –library, it is packaged as.A.

After verification, you can view the current git change status through the GIT status, and no files that need to be submitted can be added to the gitignore.

Git, status, GIT, add, GIT,, commit, -m,'first, blood'

Here you can already submit your code to the remote warehouse, but you need to add the warehouse address before submitting it

  • Add public key
Ssh-keygen

Add the generated public key id_rsa.pub to the account

Create a private index library from the pocket CocoaPods
adds the public key
Git, remote, add, origin, git@git.coding.net:coder_01/TestLib.git, GIT, push, origin, master

Before you do remote validation of podspec, you must first push tag, and tag must be consistent with the version in podspec

Git, tag, 0.1.0, GIT, push, --tags, pod, spec, --private, lint

After remote authentication, TestLib.podspec push is passed to the remote private index library. Similarly, you need to add the warehouse first, and then push

  • Creating a private index library
Create a private index library from the pocket CocoaPods
private index library
Pod, repo, add, PrivateSpecs, git@git.coding.net:coder_01/PrivateSpecs.git, pod, repo, push, TestLib.podspec, PrivateSpecs

At this point, the local index library is long

CD ~/.cocoapods/repos open
Create a private index library from the pocket CocoaPods
PrivateSpecs

The most basic production is done here, and now you can search the TestLib Library

Pod search TestLib
Create a private index library from the pocket CocoaPods
pod search

New project, pod init, modify the podfile file. Here you need to add two source, an original master repo, and a later added PrivateSpecs

Source,'git@git.coding.net:coder_01/PrivateSpecs.git', source, use_frameworks,'https://github.com/CocoaPods/Specs.git', target,'Test', do, pod,'TestLib', end

To execute pod install, you can use the TestLib framework

Tip: if the component contains pictures, audio, video, xib/storyboard, etc., the description of podspec and the wording in the code need to be changed

Go back to the podspec file

S.source_files ='TestLib/Classes/**/*'s.resource_bundles ='TestLib' => # # {['TestLib/Assets/*.png']} #;

S.source_files is used to find code, and s.resource_bundles is used to find resources.
TestLib/Classes/**/* represents all files that match all subdirectories under the TestLib/Classes folder

Pattern:*
  • * match all files
  • C* matches all files that start with C
  • *c matches all files that end with C
  • *c* matches all files that contain C
Pattern: * * *
  • * * recursively matches all subfolders

Before you load the components, you can load pictures, audio, video, xib/storyboard and other resources through the mainBundle. Now you want to get the resources through the component bundle. TestLib automatically routes the specified path resources under s.resource_bundles to bundle packages and is named TestLib.bundle

Create a private index library from the pocket CocoaPods
s.resource_bundles

However, you don’t have to put the resources under the Assets folder, which can be any folder (such as Classes or new in the directory structure), as long as you can find the resources. Similarly, if you include the resource s.source_files, write it this way:

S.source_files ='TestLib/Classes/**/*{.h,.M}'

If you don’t write this, if you include a resource file in Classes, it will cause a crash. At this point, first find the TestLib.bundle, and then load the resources from this bundle

NSBundle *bundle / / bundle resource acquisition bundleForClass:[self class]] = [NSBundle;

Podspec also has some common uses, such as subspec, dependency, vendored_frameworks, vendored_libraries, prefix_header_contents, prefix_header_file, and so on

Podspec more configuration, you can refer to Podspec Syntax Reference

Have fun!