Overview
The introduction of Cocoapods is beyond the scope of this article, and if you're an iOS developer and you don't know cocoapods, it could be wall for 30 seconds. Go straight to the topic, this article mainly describes if you publish your code to the Cocoapods code base, so that others can use the "Pod search youropenproject" command to find your code.
Before May 20, 2014, this article can be used to publish code to Cocoapods. But the passage of time, for security and other considerations, the Cocoapods team gave up the way, using this article to say the trunk way, the flow chart is shown as follows: (image from the Cocoapod official blog)
Below please follow my steps and step down, I will tell you some of the pits and how to deal with these pits:
first, registered trunk
Before registering the trunk, we need to confirm that the current Cocoapods version is new enough. Trunk requires pod in version 0.33 and above, if you do not meet the requirements, open terminal using Ruby's GEM command to update the pod:
sudo gem install Cocoapods
At the end of the update, we started registering the trunk:
Pod trunk register [email protected] ' weng1250 ' --verbose
The mailbox and user name should be reserved. User name I'm using a user name on GitHub. The--verbose parameter is designed to facilitate the output of debugging information during the registration process. After executing the above statement, your mailbox will be subject to a link with a verification of the message, if not please go to the trash bin to find, it may be blocked. Click on the email link to complete the trunk registration process. Use the following command to query your trunk server for your registration information:
Pod Trunk Me
The output of the following information indicates that you have successfully registered, you can carry out the following process:
Second, the configuration Podspec
In this section we need to do two things: 1. Add the podspec description file for your code, 2. Push Podspec file through trunk to Cocoapods server
2.1 Adding Podspec profiles
This step is exactly the same as before changing the trunk mode. What is a podspec description file? Simply let the cocoapods search engine know your code's author, version number, source code address, dependent library and other information files. Any open source code that supports cocoapods must have a podspec file. CocoaPods uses a repo in GitHub to manage all open source code that supports CocoaPods: Https://github.com/CocoaPods/Specs.
So how do you write Podspec files? The official provides a template with very detailed explanatory notes. The writing of the Podspec file is not intended to be described in detail. It is strongly recommended that you look at section three of this article, fourth fifth, because it is obsolete.
It is recommended to change the podspec of some mature open source library directly, there are many redundant properties in the generated template.
2.2 pushing Podspec files via trunk
Now that we have our own Podspec file, you need to confirm the following points before pushing the Podspec file:
1. Make sure your source code has been push to GitHub. If you do not have the push source code, you can use the terminal CD to the root directory of your local source code to perform:
Git add-agit commit-m "first commit for version 1.0.0" Git Push Origin Master
Of course, you can also use a GUI-style git client like Sourcetree to push code.
2. Make sure that the code you push is already labeled "Version Tag", which is the tag for the source code:
git tag ' 1.0.0 ' git push--tags
Only by ensuring that the above two points, cocoapods can more accurately find your repo.
Now we start uploading your Podspec file through the trunk. First CD to the directory where the Podspec file is located, execute:
Pod Trunk Push Wzlbadge.podspec
The file name is self-reserved. The above code does three things: (you can see the flow chart at the beginning of the article)
1. Verify that your Podspec file is legal. We usually verify the "Pod lib Lint" command before the trunk mode.
2, upload podspec files to the trunk server (in fact, will automatically add to the https://github.com/CocoaPods/Specs , just use the trunk way to eliminate the previous fork in pull Cumbersome operation of the request)
3. Convert your uploaded podspec file into a JSON format file
Performing the above push operation is equivalent to submitting your source code to the Cocoapods team for review, which typically takes one to two business days to complete. This mood is a bit like submitting an app to Apple for review, haha.
third, update the local pod dependency
Now that the code submission is over, why take this step? Because you don't know when it's going to be approved. You might say, "Pod search" command to find out, you know? Unfortunately, if this step is not performed, it is never known on your computer when the code is approved. For example, I have submitted my open source code Wzlbadge (as of 300+ star before press) to the third day after the pod and still can't find it using the search command:
This speed makes me feel a little wrong. So I used
Pod Setup
command to update the local pod-dependent library before executing the pod Search command (which takes about half an hour, related to the speed), the results are as follows:
This proves that the code has already been approved by the review!
So, you need to do this in this segment:
In the trunk push after a day or so, first use "Pod search" to find your code, the result of the words of joy; do not execute "pod Setup" for local dependent library updates, and then search.
Strong insert:
If not, most students will be stuck in the sentence "Setting up CocoaPods master repo" after executing the above command. My experience is a word: wait! Do not close the terminal, almost half an hour to an hour or so will be completed , prompted "Setup completed". Why did you get stuck for so long?
Pod Setup is actually doing one thing: CocoaPods is downloading the https://github.com/CocoaPods/Specs information to your computer's ~/.cocoapods directory and making the file comparison, the total data size is about 100MB, In addition to the server in foreign countries , so the speed is relatively slow. During the execution you can also open a new terminal window, CD to the ~/.cocoapods directory, du -sh * to view the download progress.
Of course, if you have obsessive-compulsive disorder that can't wait so long, there is a solution. You can refer to the "image index using Cocoapods" section of this article of Tang Qi to replace Cocoapods's mirror address with a server address such as a domestic oschina, which may improve speed. But I personally don't think it is necessary for me to take about half an hour without a ladder and be more patient.
written in the last
Trunk way is indeed much more convenient than the previous Fork->pull way, but the current online about the trunk to submit cocoapods code, so there is not much information, so only this article. I hope this article will help you.
=======================================================
Original article, reproduced please indicate the program small Weng @ Blog Park, mail [email protected], welcome you and I in the c/c++/objective-c/machine vision and other fields to start communication!
Welcome to my GitHub homepage, follow my open source code, fellow me, and welcome you to star/fork/watch my open source project.
=======================================================
"Original" IOS: teach you to release code to Cocoapods (trunk mode)