iOS开发日常-CocoaPods秘籍之【发布自己的项目至Specs repository】

Create the Project

  The pod lib command is an important tool that we’ll use for two purposes during the creation process:

 1. pod lib createwill actually help give you a jump start by providing a standard directory structure with a bunch of boilerplate files necessary for a high quality pod. pod lib create isn’t the only way to create your pod, but it is the easiest.

 2. pod lib lint will validate that everything is okay with your pod and that it’s ready to use by CocoaPods.

  • Open a Terminal window, navigate to a working directory, and execute the following commond:
    pod lib create DQSKit
    

Updating Your Pod’s Metadata

  • The pod lib lint command will automatically validate the .podspec file to ensure it complies with best practices. Or, if you’re lazy, you can also use it figure out the bare minimum you need to do to create a proper .podspec file.

    pod lib lint DQSKit.podspec
    

  • To get the url, It’s time to push your project to a public repository on GitHub. While there are other options for hosting your pods, GitHub is by far the most common. To push your project to GitHub, browse to GitHub, login or create an account, and create a New Repository called DQSKit. Then, from the command line, execute the following commands:

    git status
    git add -A
    git commit -a -m'Initial Commit'
    git remote add origin https://github.com/shengguoqiang/DQSKit.git
    
  • Fill in the info necessary (e.g. summary mentioned above), and execute the command line again:

Adding Code

You now have the basic shell of a pod, but it doesn’t do anything. It’s time to add some functionality. The nifty thing about the sample project that CocoaPods created for you is that you can simultaneously write code for both the pod and the example project.

  • First, find the file ReplaceMe.swift under Pods/Development Pods/DQSKit and delete it.

  • Next, create a new Swift file in the directory DQSKit/Classes

  • To ensure it’s easy for other developers to understand how to use DQSKit, add some sample code to the example project. Open DQSKit/Example/DQSKit/ViewController.swift and make it look like this:

  • At this point, you’ll see Xcode complaining with a lot of errors in ViewController.swift. This is because the pod for DQSKit isn’t installed on the example project yet. To do that, switch to the command line and from the root of the DQSKit directory execute the following command:

Making Your Pod Available

  Now that you have a fully functional pod running on your local machine, it’s time to make DQSKit available to others for inclusion in their projects. At a high level, this is accomplished by getting your new pod into the public Specs repository.
  The Specs repository is the public place on GitHub where all public pods are indexed.

  • Step1~Tagging
    Tag your most recent commit and push it to the remote.

    	git tag 0.1.0
    	git push origin 0.1.0
    


    This step indicates that you are marking this commit as a specific release of your pod. The name of the tag should match s.version in your .podspec file. The next step will validate this.

  • Step2~Validation
    Next, run the following command from the command line to verify that everything is configured correctly between where your source code is stored and your .podspec file:

    pod spec lint DQSKit.podspec
    

  • Step3~Pushing to Specs Repository
    Finally, push the spec to the Specs repository by executing the following command:

    pod trunk push DQSKit.podspec
    

  • If you haven’t registered CocoaPods Trunk, Step3 would fail.
    CocoaPods Trunk is an authentication and CocoaPods API service. To publish new or updated libraries to CocoaPods for public release you will need to be registered with Trunk and have a valid Trunk session on your current device.

      pod trunk register 18705147127@163.com 'dqs' --description='大强神' 
    

    You must click a link in an email Trunk sends you to verify the connection between your Trunk account and the current computer. You can list your sessions by running pod trunk me.

    Trunk accounts do not have passwords, only per-computer session tokens.

Usage

https://blog.csdn.net/FTD_SL/article/details/85766565

Reference

https://code.tutsplus.com/tutorials/creating-your-first-cocoapod--cms-24332

猜你喜欢

转载自blog.csdn.net/FTD_SL/article/details/85789651