An overview,

Cocoapods is the most popular version dependency tool for iOS development. Developers can save a lot of time by using Cocoapods for project dependency management. You’ve all tried to manage your projects through Cocoapods, but how do you distribute your code to Cocoapods and make it searchable? Here’s a look at trunk access and the pitfalls you might encounter in the process.

Second, the registration

The first step is to register the trunk. Before registering the trunk, verify that the current CocoaPods version must be at least 0.33. If the version is earlier than this, open the Terminal command to update the pod:

sudo gem install cocoapods
Copy the code

If the OSX version is later than 10.11, use the following installation command

sudo gem install -n /usr/local/bin cocoapods
Copy the code

After the version update is over we start registering trunk:

Pod Trunk register < mailbox > <'Username'> --description='macbook pro'
Copy the code

The email address is the most important, because pod will send an activation email to your email address after registering, so the email name will act as your trunkID. The –description parameter is recommended by Cocoapods. If you log in to the trunk on another device in the future, it is also an optional parameter. Click the registration link in the mailbox and use the following command to query your registration information from the Trunk server.

pod trunk me
Copy the code

The registration is successful if the following information is displayed:

Configure podSpecs

3.1 Adding a PodSpec file

Podspec files are your project profile and let cocoapods search engine know about author name, project overview, version number, source code address, dependency libraries, etc., so every project on Cocoapods will have a PodSpec description file. Cocoapods manages all the code supporting Cocoapods via a single repo on Github github.com/CocoaPods/S… . How do I create a PodSpec file? We can do this by:

pod spec create <name>
Copy the code

To create a podSpec file, the official spec file is very redundant and not very concise. If you are writing an official Spec file for the first time, you should check it out. Finally, I recommend that you use github’s podSpec libraries to configure your own podSpec files. Here you can share your own podspec files for learning and sharing.

Pod::Spec.new do |s|
s.name        = "ipaynowplugin"
s.version      = "1.7.3.42"
s.summary      = "ipaynowplugin SDK"
s.description  = <<-DESC Help developer to quickly intergrate variety of payment methods DESC
s.homepage    = "http://www.ipaynow.cn"
s.license      = "MIT"
s.author      = { "Hstripe"= >"[email protected]" }
s.platform    = :ios.'6.0'
s.source      = { :git= >"https://github.com/Hstripe/libipaynow.git".:tag => s.version }
s.default_subspec = 'Core'
s.requires_arc = true
s.subspec 'Core' do |core|
core.source_files = "lib/*.h"
core.public_header_files = "lib/*.h"
core.vendored_libraries = "lib/*.a"
core.resource = "lib/*.bundle"
core.frameworks = "CoreGraphics"."CoreTelephony"."QuartzCore"."SystemConfiguration"."Security"."Foundation"."UIKit"
core.ios.library = 'z'.'sqlite3.0'.'c++'.'stdc++'
core.xcconfig = { 'OTHER_LDFLAGS'= >'-ObjC' }
end

s.subspec 'Alipay' do |ali|
ali.ios.vendored_frameworks = "lib/Channels/AliPayPlugin/AlipaySDK.framework"
ali.resource = "lib/Channels/AliPayPlugin/AlipaySDK.bundle"
ali.dependency "ipaynowplugin/Core"
ali.frameworks = "CoreMotion"
end

s.subspec 'Weixin' do |wx|
wx.ios.vendored_libraries = "lib/Channels/WechatPlugin/*.a"
wx.source_files = "lib/Channels/WechatPlugin/*.h"
wx.public_header_files = "lib/Channels/WechatPlugin/*.h"
wx.dependency "ipaynowplugin/Core"
end

s.subspec 'Unionpay' do |up|
up.vendored_libraries = 'lib/Channels/UPPayPlugin/*.a'
up.source_files = 'lib/Channels/UPPayPlugin/*.h'
up.dependency 'ipaynowplugin/Core'
end

s.subspec 'ApplePay' do |ap|
ap.source_files = 'lib/Channels/UPApplePay/*.h'
ap.public_header_files = 'lib/Channels/UPApplePay/*.h'
ap.vendored_libraries = 'lib/Channels/UPApplePay/*.a'
ap.dependency 'ipaynowplugin/Core'
ap.frameworks = "PassKit"
end
end
Copy the code

The following is a brief description of several parameters:

S.name. is the name of your project, which can be searched by using the pod search command. S. Sion The current version number of the project. Summary description of s. Summary project; A detailed description of the S. Description project; The s.license file, which is required by Cocoapods, will not be verified if it is not present; S.ource Project source code location, typically a Github address; The default subpackage loaded by the s.fault_subspec project. Since my project is made up of multiple packages, I will add this parameter. If the project has only one package, I do not need to specify this parameter.Copy the code

The following parameters are important:

Core.source_files Main file of the project; Core.public_header_files Exposed header files; Core. Vendored_libraries Static libraries for the project (open source or closed source depending on the project type); Core. resource Resource files (images, etc.) used by the project; The framework framework of a system that depends on core.frameworks; Library Lib library file of the system on which core.ios.Copy the code

Proceed to the next step after the above parameters are configured

3.2 Local Check

After configuring the parameters of the podSpec description file, it is a good idea to perform a local check of the podSpec file by running the following command:

pod lib lint --verbose
Copy the code

Verbose is used to output debugging information to help you find errors. If there are any errors, you can modify the podspec content based on the error information in Build Failed. If the input terminal is complete, the following information is displayed:

3.3 Push podSpec files through Trunk

1. Before trunk push, make sure you have uploaded your project files to Github. If you haven’t uploaded the source code yet, you can use the terminal CD to upload the code to Github

git add .
git commit -m "Version Content"
git push origin master
Copy the code

2. Tag the code you upload so that Cocoapods can find your version more accurately

git tag 'tagNum'
git push --tags
Copy the code

After all the preparatory work is done, the core work trunk push begins

Pod Trunk push yourprojectName. podsepc --verbose File name please change to your podspec nameCopy the code

This code does three things: 1. Verify that your PodSpec file is valid, which we did before trunk using the “pod lib Lint” command; 2, trunk podspec uploading files to the server, finally uploaded to https://github.com/CocoaPods/Specs; 3. Convert your podSpec files into JSON files.

Lint files via local pod lib lint files generally do not have any problems, the most likely problem is that the network is not strong, resulting in GitHub connection difficulties. Once the upload is successful, you can use the pod search command to search for your project.

If Pod Search can’t find its own project, you’ll need to manually synchronize your local Spec repo with POD Setup again, which is always a long and painful process, so it’s recommended to keep the VPN on when updating.

Iv. Upgrading of follow-up projects

When you make changes to your project, you want to update the version in Cocoapods as well. At this point, you need to update your PodSpec description file to fit your current version. You’ll also need to tag your GitHub version and make sure it matches s.Sion in your Podspec.

By the way, there is no “regret pill” in podSpec. If you find that your current version of your PodSpec doesn’t match your description file, you can’t change your current version of your PodSpec. You can only change it in the next version. So be careful when filling out your PodSpec file.

5. Reference documents

www.cnblogs.com/wengzilin/p…

www.jianshu.com/p/0b516ee65…