How to publish their open source framework to CocoaPods

In the development process, often used to the third framework, we adopted a pod install command, it is convenient to add the framework of the third party to our own projects.
if we want to write their own components or libraries open source, so that others can also be installed by the pod install command of the framework of how to do it? Below, I will teach you step by step to their pods to CocoaPods. If you are still not very understanding of CocoaPods, it is recommended that you take a look at this article: using CocoaPods to do iOS program dependency management

Create a Podspec description file for your project

Below I will be through a project called HUPhotoBrowser to explain the whole process.
project released to GitHub, you need to hit tag. Then we initialize a Podspec file in the root directory of the project:

Pod spec create HUPhotoBrowser

This command will generate a file named HUPhotoBrowser.podspec. Open the file with the editor, which has a very rich documentation. The following describes how to declare the third party library code directory and resource directory, as well as the third party libraries rely on the IOS core framework and the third party library. This is my podspec file:

Pod:: Spec.new do |s| s.name = "HUPhotoBrowser" s.version = "0.0.2 s.summary =" photo "browser for ios." s.homepage s.license = "https://github.com/hujewelz/HUPhotoBrowser" = "MIT" s.author "Jewelz Hu" = {=>}; "[email protected] 163.com": IOS, s.platform = "7" s.source = {git: => https://github.com/hujewelz/HUPhotoBrowser.git "tag: =>" 0.0.2 "}; s.source_files =" HUPhotoBrowser "," HUPhotoBrowser/**/*.{h, m} "s.framework =" UIKit "# s.frameworks =" SomeFramework "," AnotherFramework"

S.name is the name of our library, s.version library source code version number s.summary is a brief introduction on our library, s.homepage statement library homepage, s.license is the authorized version, s.author is the author of library. S.platform is a software platform supported by our library, which is useful for our final submission. S.source declaration of the original code address. I’m hosting here on GitHub, so here’s the address copy.

How to publish their open source framework to CocoaPods
screen snapshot 2016-02-26 PM 3.02.58.png

for many third party libraries, at the time of the release will be marked with a tag, such as the version of 0.0.1 will be marked as a 0.0.1 tag, you can also choose a new commit code as the library 0.0.1 version, so this is the final source:

{git => "https://github.com/hujewelz/HUPhotoBrowser.git", commit =>'65584b0e0b08e01f83e66d487180c164b5182409'}

I still use tag here, so here I am:

{git => "https://github.com/hujewelz/HUPhotoBrowser.git", "tag"; "0.0.2"} "=>"

After our library has a new version, we can modify the corresponding version and source.
s.source_files declared the location of the source code of our library, so this place can not be wrong.
look at my directory structure:

How to publish their open source framework to CocoaPods
screen snapshot 2016-02-26 PM 3.15.07.png

so the root directory under the HUPhotoBrowse folder is the original library directory.

S.source_files = "HUPhotoBrowser", "HUPhotoBrowser/**/*.{h, m}"

The hierarchy of directories must be consistent with the code base. The first part of the past can not be used, because I am here after a part of the HUPhotoBrowser/** is consistent with the previous, the file under the specified directory will be compiled. If there are some resource files (such as pictures, etc.) in the directory, these files do not need to be compiled. You can use the s.resourcs declaration. *.{h, m} is a string similar to regular expressions that match all files with.H and.M extensions.
s.framework declared that the core library is dependent, I only use UIKit, so it is:

S.framework = "UIKit"

If your project relies on multiple libraries, you can use the

S.frameworks = "SomeFramework", "AnotherFramework"

Of course, we can also rely on the development of Libraries in the third party libraries, such as JSONKit, then you can do the following statement:

S.dependency "JSONKit", "~> 1.4"

If there are more than one need to fill multiple s.dependency.
to edit the podspec file, you need to verify that the file is available, if there is any WARNING or ERROR are not, it will not be added to the Spec Repo, but Xcode WARNING can exist, verify the need to execute the commands:

Pod spec lint PodName.podspec

When you see HUPhotoBrowser passed validation., indicating that the adoption of the validation. When you in the detection of podspec, pod spec lint xxx.podspec if the direct use of words, wrong it will only direct a red The spec did not pass validation, due to 1 error. to tell you the number of error and warning, but not the specific points out your mistake where you can. Behind this command with –verbose that will tell you the specific error information. According to this, it prompts you to solve the wrong information on it.

After editing the podspec file, you can save the podspec file to the machine’s ~/.cocoapods/repos/master/Specs directory for your own use, or submit it to the CocoaPods/Specs code library. Below we save it to the machine:

How to publish their open source framework to CocoaPods
screen snapshot 2016-02-26 PM 3.44.31.png

can look at the following can be found through the search library:

How to publish their open source framework to CocoaPods
screen snapshot 2016-02-26 PM 3.48.06.png

also needs to rely on the HUPhotoBrowser library project, you can add the following to the project’s Podfile file

Pod'HUPhotoBrowser','~0.0.2'

Save the file and install the HUPhotoBrowser library with pod install.

Through the above steps to create a Pod library can only be used for their own use, the following will continue to explain how to submit to the CocoaPods/Specs code library, so that others can also be installed by pod install.

CocoaPods Trunk released its own Pods

After using the trunk cocoapods, CocoaPods requires more than 0.33 version, with pod –version view version, if the version is low, need to update.

Register Trunk

$pod trunk [email protected] Therox''Orta --description='macbook register air'

We need to be replaced in the registration of their own mailbox and user name, everything will be successful if a message, click on the link in the email to verify:

Pod trunk me
How to publish their open source framework to CocoaPods
screen snapshot 2016-02-26 PM 4.05.42.png

of course, if your pod is maintained by multiple people, you can also add other maintainers:

$pod trunk ARAnalytics add-owner [email protected]

After the above work is done, we can start the trunk push.

Trunk push

Pod trunk push command will first verify your local podspec file (if there is an error), then upload the spec file to the trunk, and finally you will be uploaded to the podspec file to the required file. Execute commands in the project root directory (including.Podspec):

Pod trunk push

If you are wrong in the trunk push process, check the error information carefully. I used to use the podspec file described in the version does not have API, then modify the podspec file s.platform =: IOS, “7” on it.

How to publish their open source framework to CocoaPods
screen snapshot 2016-02-26 PM 4.12.59.png

if you can see the above results show that the upload is successful. We can also see the conversion of the JSON file in the local ~/.cocoapods/repos/master/Specs directory,

How to publish their open source framework to CocoaPods
screen snapshot 2016-02-26 PM 4.16.56.png

so far our entire production of their own open source library process is completed, there will be a new version only need to modify the project under the root directory of the podspec file on the line, and then re execute the pod trunk push command.

Last

Finally, a summary of the process:

  1. After the release of the open source library, you need to hit tag
  2. Go to the project root directory to create the podspec file pod spec create PodName
  3. Edit the relevant information in the podspec file, there are two more important places s.source and s.source_files, you can verify the error: pod spec lint PodName.podspec
  4. Registered pod trunk$trunk [email protected]’Orta Therox’–description=’macbook air’ pod register
  5. Publish to pod trunkpod push [NAME.podspec] the command is executed in the directory containing the.Podspec file in trunk
  6. Update pod library pod setup if pod trunk is not able to successfully pod search into its own library, the command can be executed by push.

Last last

Ha-ha。 Well, I admit that I’m here to advertise. In the example of HUPhotoBrowser is an open source of a picture browser library, the use is very simple, a line of code to achieve image browsing, support for local and network images. Hope that we can support you, welcome to star. If you have any questions, you can directly issue me. Finally, I hope we can make progress together. Project address: HUPhotoBrowser