Upload personal third party library to cocoapods

Time:2021-2-18

Upload personal library to cocoapods

1.1 creating projects in GitHub

  • Fill in the project name
  • Fill in the project description
  • Set library public
  • Add the certificate and readme file. The certificate can also be downloaded after the project is createdCreate new fileAnd inputLICENSE, click theChoose a license templateSelect the required certificate and add it

After setting, clone directly to local, and copy the project code into this folder

1.2 create podspec file

1.2.1 clone to local folder through terminal
cd xxx
1.2.2 creating podspec file
pod spec create xxx
  • The name of the library created by XXX, such asAlamofire
1.2.3 configure podspec file
@version = "0.0.1"
Pod::Spec.new do |s|
s.name = "MCircleBoard"
s.version = @version
s.summary = "MCircleBoard"
s.description = "MCircleBoard is a dash board."
s.homepage = "https://github.com/MichaelLynx/MCircleBoard"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "xxx" => "[email protected]" }
s.platform = :ios
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/MichaelLynx/MCircleBoard.git", :tag => "v#{s.version}" }
s.source_files = "Code/*.swift"
s.resources = ["Code/*.xcassets"]
s.swift_version = "4.0"
s.requires_arc = true
s.framework = "UIKit"

end
  • If there is a dependent library, add it, such as:s.dependency "AFNetworking", '~> 3.0'
  • The more important fields are:nameversionsummaryhomepagelicenseauthordeployment_targetsourcesource_filesrequires_arc
  • source_filesIt’s better to put the files to be uploaded in a special folder
  • Add resources to the Library: add bundles and set propertiesresource\`resources\\resource_bundles`

Add resources to spec:

spec.resource = 'Code/MCircleBoardIcon.bundle'
spec.resources = ['Images/*.png', 'Sounds/*']
spec.resource_bundles = {
    'YourBundleName' => ['MapView/Map/Resources/*.png'],
    'OtherResources' => ['MapView/Map/OtherResources/*.png']
  }

How to call pictures in a bundle:

var bundle = Bundle(for: theClass.self)
if let resoucePath = bundle.path(forResource: "bundleName", ofType: "bundle"), let resouceBundle = Bundle(path: resoucePath) {
    bundle = resouceBundle
}
let image = UIImage(named: imageName, in: bundle, compatibleWith: nil) ?? UIImage()
  • To set it as a third-party library, you can only get pictures in this way, not like the way in the main project
  • theClass: project name;bundleName: the name of the corresponding bundle

Podspec Field Description:

field effect
name The name of the library
version Version number, which must correspond to that on GitHub. See the following steps
summary A brief introduction of the library
homepage The home page of this library corresponds to the address on GitHub
license What kind of license should be used, corresponding to the one selected when creating GitHub
author author
deployment_target The minimum IOS version of the library is available
source Data source, corresponding to youcloneThe one that I used when I was a kidHTTPSLink address for
source_files Which files are uploaded to pods
requires_arc Is it used in arc environment
dependency What other third-party libraries are referenced by the library

1.3 create release version on GitHub

  • After the podspec file is verified to be correct, you need to update the project to GitHub first
  • After updating, release to create a new version,Tag versionStart with V, followed by version number and titlerelease titleNeed to fill in
  • If the code is changed during the operation, you need to delete the release, upload the code and re create the release

1.4 register trunk account and upload project

1.4.1 registration of cocoapods account

If you have successfully registered your account, skip this step

Input command at the terminal:

Pod trunk register email address' user name '- Description ='description information'
or
Pod trunk register email address' user name '-- verb
  • Do not write the information after the user name
  • After successful registration, you will be prompted to go to the mailbox to verify the information
  • The registration information should be consistent with GitHub to facilitate memory
  • The email address and user name registered here are the author of podspec

After verification, enter the following command in the terminal to confirm whether the registration is successful

pod trunk me
  • If the user information appears, the registration is successful
1.4.2 verify podspec file

If you confirm that the podspec file is OK, you can not verify it

If the configuration is correct, you will be prompted after entering the verification command:passed validation.

After the podspec file configuration is completed, you can input instructions at the terminal for verification

pod spec lint XXX.podspec
  • If there is an error in the verification result, it must be processed according to the requirements; if there is a warning, it can be processed or ignored
  • hinderXXX.podspecCan be omitted
  • pod lib lintOnly verify whether your pod can pass the verification locally;pod spec lintVerify whether your pod can pass the verification locally and remotely.pod lib lintIt can be omitted and used directlypod spec lintVerify
1.4.3 upload cocoapods

Enter the following command to upload the code to cocoapods:

pod trunk push

If there is awarning, you can use--allow-warningsIgnore warning:

pod trunk push --allow-warnings

Appears after completionTell your friendsThe words prove that the upload is completed and can be passedpod search XXXCommand to verify whether the upload is successful.

If you don’t find it, you can go through thepod repo updateUpdate the local pod library, and then search.

If you have downloaded the old version of the library in advance, you can CD it directly to the project and download itPod update third party library nameEven if we can’t find it for the time being,pod updateIt can still be effectively updated to the latest version.

The following is a third-party library created by myself. Welcome to click star and exchange with each other.
MCircleBoard

Recommended Today

Rust and python: why rust can replace Python

In this guide, we compare the rust and python programming languages. We will discuss the applicable use cases in each case, review the advantages and disadvantages of using rust and python, and explain why rust might replace python. I will introduce the following: What is rust? What is Python? When to use rust When to […]