Publish components to cocoaPods

1, Create warehouse

  • The warehouse name is the component name (create a new project on the GitHub platform: the name is < name >)


After creation, put it aside first;

2, Create local component code base

  • Create a folder to store components locally
  • Open the terminal and cd to the folder first;
  • Pod lib create < component name >
Example: pod lib create  MyThirdPartySDK

After execution, a series of choices will appear. Follow the steps to select and then OK;

1.Whatisyour email?What platformdoyou want to use??[iOS/macOS]//Select platform:
2.IOSWhat languagedoyou want to use??[Swift/ObjC]//Select language:
3.ObjCWould you like to include a demo applicationwithyourlibrary?[Yes/No]//Generate a demo automatically:
4.YesWhich testing frameworks will you use?[Specta/Kiwi/None]//None
5.Would you like todoview based testing?[Yes/No]//No
6.Whatisyourclassprefix?//Prefix of generated class

fixed: 6 maybe not

Finally, a component project is generated, and the project will be opened automatically; In the project directory, there is an Example directory. Open it to see the directory structure;

3, Add components to a component project

In this project, the Classes and Assets folders are where the component files are placed;

ReplaceMe.m is a file that is automatically generated when a project is generated and can be deleted;

Put component files in Classes and Assets components in resource files;

Component file directory.png

4, Add the pod component to the project

  • cd Example, go to the Example directory where there are Podfile files;
  • Execute pod install;

After execution, you can see that the components have been pod added to the project in the project directory;

5, Index file XXX..podspec

Open the XXX..podspec file of the project and modify it as needed; do |s|             = 'MyThirdPartySDK' //SDK name
  s.version          = '0.1.0' //The version number should be consistent with the tag on GitHub
  s.summary          = 'A short description of MyThirdPartySDK.' //brief introduction
  s.description      = <<-DESC
  TODO: Add long description of the pod here. //describe
  s.homepage         = '[GitHub name] / MyThirdPartySDK '
  # s.screenshots     = '', ''
  s.license          = { :type => 'MIT', :file => 'LICENSE' } //Open source default certificate           = { 'XXX' => '' } //author
  s.source           = { :git => '[GitHub name] / mythirdpartysdk. Git ': tag = > s.version.to_ S} / / project address and tag
  # s.social_media_url = '<TWITTER_USERNAME>'
  s.ios.deployment_target = '9.0'
  # s.source_ Files = 'mythirdpartysdk / classes / * * / *' / / source file of pod Library
  s.vendored_frameworks = "MyThirdPartySDK/Classes/*.framework" //Path of framework in pod Library
  # s.resource_bundles = {
  #   'MyThirdPartySDK' => ['MyThirdPartySDK/Assets/*.png']
  # }
  s.resource         = "MyThirdPartySDK/Assets/*.bundle" //The specified resource is copied directly to the client destination
  s.pod_target_xcconfig = { 'VALID_ARCHS[sdk=iphonesimulator*]' => '' }
  # s.public_ header_ Files = 'pod / classes / * * / *. H' / / header file exposed to user project by pod Library
  #s.frameworks = 'UIKit', 'MapKit' / / dependent system library
  s.dependency 'AFNetworking', '~> 4.0.1' //Dependent third party libraries

6, Submit to remote warehouse

Execute under the project root directory, that is, in the folder where XXX.podspec is located;

git add .
git commit -m "Add component for the first time"
git remote add origin <GitHub Warehouse address>
git push origin master
git tag <Version number> (and XXX.podspec Consistent in, e.g. 0.1.0)
git push --tags

7, Validate cocoapods index file

Execute under the project root directory, that is, in the folder where XXX.podspec is located;

pod spec lint --verbose --allow-warnings
pod spec lint --skip-import-validation --allow-warnings --use-libraries 

Verification successful:

XXX.podspec passed validation.

Verification failed:

The error description will be marked and can be handled according to the description;

[!] The spec did not pass validation, due to 1 error.

8, Release

  • Execute under the project root directory, that is, in the folder where XXX.podspec is located;
  • Check whether to register trunk first;
pod trunk me

Registered trunk screenshot.png

  • If not, register first
pod trunk register <mailbox> "<name>" --verbose
  • After registration, a confirmation email will be sent with a link. Click to confirm;
  • Publish after registration; (under the project root directory)
pod trunk push xxx.podspec 
pod trunk push xxx.podspec --allow-warnings //Allow warning
pod trunk push xxx.podspec --allow-warnings --skip-import-validation //Skip verifying whether the pod is imported

Published successfully

Updating spec repo `trunk`
Validating podspec
  -> MyThirdPartySDK (0.1.0)
Updating spec repo `trunk`
 🎉  Congrats
 🚀  MyThirdPartySDK (0.1.0) successfully published
 📅  January 26th, 00:41
 👍  Tell your friends!

9, Verify

  • After cocoapods is successfully published, you can use the search command to search;
pod search <library name>

Search succeeded

-> MyThirdPartySDK (0.1.0)
   A short description of MyThirdPartySDK.
   pod 'MyThirdPartySDK', '~> 0.1.0'
   - Homepage:[GitHub name] / MyThirdPartySDK / / corresponding to XXX.podspec
   - Source:[GitHub name] / MyThirdPartySDK.git
   - Versions: 0.1.0 [trunk repo]

If the search fails, a red line will appear, indicating that it cannot be found

Reason not found:

1 - after successful release, it needs to be separated for a period of time, which may be still under review;

2 - you can find it by executing the following in the morning;

[!] Unable to find a pod with name, author, summary, or description matching `MyThirdPartySDK `

Posted on Fri, 26 Nov 2021 03:37:17 -0500 by s0me0ne