On second thought, I realized that I haven’t written a new article in a long time, and some friends came up to me and said that MY Nuggets haven’t been updated in a long time, which is not true, I’ve been maintaining and updating iOS development: CLUIKit and iOS development: “CLFoundation” is a wheel I made by myself, but there is no update date for the article, so I can’t see my update. I hope nuggets can consider adding an update date ~~

Buy him a star dad

If you think it’s great, I can have a star dad, thank you

In addition to busy working on the project these days, there is another thing is to make CocoaPods library, although this thing is easy to use, not research is good, a study will find that it is really…..

Made a day or two, searched N many Baidu and Google, also consulted a lot of big guy, finally make a drum out, the following directly on the article, not so much nonsense.

Create the PodSpec file

Use the terminal to find the folder where you want to create the CocoaPods development library

cdThe Project folderCopy the code

After finding the corresponding path, enter the command to create the PodSpec file

Pod Spec create Library nameCopy the code

Edit the podSpec file

When you open the.podSpec file, you’ll see a number of comments that correspond to your library name. Choose to delete or not delete them as you like, but delete them all for demonstration purposes.

Here are the parameters:

  • Name: indicates the database name. This parameter is mandatory
  • Version: specifies the version number
  • Summary: A summary of the library
  • Description: Optional description of the library
  • Homepage: the homepage of the library, optional
  • License: specifies the open source agreement. This parameter is mandatory if the open source agreement is available
  • Author: The author, mandatory. See the introduction later in the article for more details
  • Platform: Specifies the lowest supported system version. This parameter is optional
  • Source: specifies the resource address. This parameter is mandatory
  • Source_files: resource files. This parameter is mandatory
  • Exclude_files: Optional
  • Requires _arc: Specifies whether the command is arc. This is optional
  • Frameworks: System frameworks that need to be associated
  • Dependency: Third-party libraries to be associated with

Check out CocoaPods for more details

For example, cluikit. podspec relies on only three libraries, MJRefresh, CLFoundation, and navigation.

This would be appropriate for a single library, such as MJRefresh, CLFoundation, or navigation, but if we need to split several sub-modules for developers to choose from, there are two options:

  • Open one moreGitWarehouse, separate storage
  • By writingpodspecFile splitting techniques.

Here we recommend the second option.

Write podSpec files to advance

The best example of this is AFNetworking. Podspec. If you have written all of your own, you can use this library as a reference:

But if we’re relying on a third-party library or Framework, this might not be the case, like clmapkit. podspec, which relies on GoogleMaps and may be compatible with other map libraries in the future, so we’ll have to break it down into N submodules. And to write for:

  • ** Subspec: ** The label of the submodule with a customizable name
  • static_framework:Static library tags that represent the ones we depend onFrameworkIt’s static.

One thing to note here is the source_files tag. In the GoogleMap submodule, we write it according to our file hierarchy. For example, the GoogleMap module of the CLMapKit library, The hierarchy is CLMapKit/forward/CLGoogleMapViewController, Google finally to Shared file, so we must write as shown in FIG. Locked here.

And write the dependent libraries for the GoogleMap subspec:

  • dependency: GoogleMaps

If we need it in the vault. Bundle, then we need to add a Resource tag:

  • resource: Classese/BundleName.bundle

Verify the PodSpec file

Once we have written our PodSpec file, we need to verify it locally:

pod spec lint
Copy the code

We don’t see any error message at this time, so we are ok. If we don’t want to warn, we can carry the keyword –allow-warnings.

Publishing third-party libraries

After we have written the above and verified the PodSpec file, we are ready to publish our library. We will only show how to publish the open source library, not the private library.

Create publicGitwarehouse

First, you need to create a Git repository, most of which is GitHub. How to create and clone a Git repository is not necessary.

Once all the code files and podSpec files have been uploaded, we’ll move on.

Create a Git Tag

Podspec has a Tag called version, which is used to Tag the version of the pod library. This Tag should not overlap with the version number of the pod library.

To create a Git Tag, go to the Clone folder and use the command to create it:

git tagThe version numberCopy the code

Once created, we need to Push the Git Tag onto GitHub, using the Push command:

git push origin --tags
Copy the code

Remember when creatingGit TagBe sure to complete all operations before proceeding, otherwise it will causeGit TagOut of sync with content.

Delete the Git Tag

Git Tag: Git Tag: Git Tag: Git Tag: Git Tag: Git Tag

git tag- d version numberCopy the code

If you want to delete a Git Tag from a remote repository, you can use the remote delete command:

git push origin --deleteThe version numberCopy the code

This way we can remove the Git Tag from the remote repository.

Query Git Tag

If you need to query an existing local Git Tag, you can use the query command:

git tag
Copy the code

If we need to query the remote repository, we can use the branch specified by the query to view:

git show origin
Copy the code

How to view remote warehouse temporarily not foundTagCan only be used in the above way.

Registered CocoaPods

The last thing to do before publishing is to register CocoaPods. You can do this using the following command:

Pod Trunk Register Mailbox'nickname'
Copy the code

All we have to do is, You get an email in your mailbox, and when we open that link, if the website shows a picture that says “You can go back to your terminal new.” then we can go to the next step. Release our CocoaPods library.

Release CocoaPods

Go back to our first library directory (the one with the.podspec file) and use the Trunk command:

pod trunk push
Copy the code

If we find several Warnings while verifying, we need to add a keyword:

pod trunk push --allow-warnings
Copy the code

If we want to see more details, we can add another key word:

pod trunk push --allow-warnings --verbose
Copy the code

If we find the error in the figure during detection:

Then we need to add another key word:

pod trunk push --allow-warnings --use-libraries
Copy the code

Finally, we enter all the commands and see the picture, which indicates that our library push is successful:

Find sent libraries

Json file is not updated. In this case, we can manually delete the file. Go back to the search, you can search.

The file path is in commonly: / Users/your user name/Library/Caches/CocoaPods /

PS: Delete and search again. It will take some time. Please be patient.

supplement

For more information about CocoaPods tags, visit the CocoaPods Guides to find out if there are bugs in CocoaPods, and leave a comment on Issues at GitHub CocoPods.

doubt

While working on CocoaPods, I had a question about how to create a PodSpec file that would associate different third-party libraries without causing conflicts between them, such as auta 2D maps and Auta 3D maps, which would cause conflicts with the Framework.

In addition, I can freely choose from the large Podspec to import autord 2D map and Autord 3D map into the project. I don’t know whether CocoaPods doesn’t support it or I haven’t studied it yet. If possible, I hope you can help me out.