Cocoapods is a package management tool developed for iOS. This article focuses on how you can use it to manage your own or your company’s component libraries. The main process includes: 1, create private library space Repo 2, create POD project 3, commit pod to Repo

Create a private Spec Repo

A Spec Repo is a collection of all Pods and is a Git repository. For example, GitHub projects managed through Cocoapods will be in the ~/.cocoapods/repos directory by default. So we need to create a similar Spec Repo. 1. Create a private repository on a Git platform, such as Github/Gitlab/Coding, and get a. Git link. 2. Add the Spec Repo to the Cocoapods Repo and run the following command

# pod repo add [Private Repo Name] [Git clone URL]
$ pod repo add YourSpecs https://github.com/xxx/yourSpecs.git
Copy the code

On success you will see the /yourSpecs folder in the ~/.cocoapods/repos directory.

Create podspec

1. Create template libraries
$ pod lib create testLib
#.
# Running pod install on your new library.
#.
# We will start you off by opening your project in Xcode
Copy the code

In this step, you need to answer questions as prompted to generate a template project. After the success will automatically perform pod install and xcode automatically open Example/testLib xcworkspace

2. Create a project repository and associate it with Git remotely
# cd testLib project
$ git remote add origin https://github.com/xxx/TestLib.git  Add remote repository
$ git push origin master     Commit to the remote repository
Copy the code
3. Develop POD projects

Import the source code into Pod/Classes. After Pod update in Example, you will see the added file in the Pods subproject.

Commit the POD to the Repo

When the POD component is developed, it needs to be tested and submitted to the Repo.

1. Configure the PodSpec file

Open the. Podspec file and change s.ource to your Git path. And information about homepage and version.

s.source = { :git= >"https://github.com/xxx/TestLib.git"}
Copy the code
2, submit the code, marking
$ cd testLib/
$ git add .
$ git commit -s -m "Initial Commit of Library"
$ git remote add origin https://github.com/xxx/TestLib.git
$ git push origin master
$ git tag -m "tag message"0.1.0 from
$ git push --tags
Copy the code
3, validation,
$ pod lib lint
$ pod lib lint TestLib.podspec --sources='https://github.com/CocoaPods/Specs.git,https://github.com/xxx/yourSpecs.git' # associated with internal POD validation
#--allow-warnings Ignore warnings
#-verbose Details about the progress
Copy the code

TestLib passed validation.

4, submit

Submitting a PodSpec to the Spec Repo must ensure that the PodSpec is validated. The submission command is:

$ pod repo push yourSpecs testLib.podspec  The local Repo name is preceded by the PodSpec name
Copy the code

After a successful ~ /. Cocoapods/repos/will see testLib yourSpecs.

Use the pod you made

After completing this series of steps, we are ready to use the private Pod in a formal project. Just add the following configuration to your project’s Podfile:

source 'https://github.com/xxx/yourSpecs.git'
pod 'testLib'.'0.1.0 from'
Copy the code

Maintain Pod procedures continuously

  • 1, modify the Pod code (import library needs to be in the example Pod update after the spec file configuration.
  • Example 2
  • 3. Write readme and Update documents
  • 4. Modify the podSpec file version, etc
  • 5, verify command: pod lib lint
  • TestPod project reference test
  • 7. Submit the subproject code to the remote end
  • 8, marking
    • Git tag -m “first release” 0.1.0
    • git push –tags
  • 9. Synchronize to Specs
    • pod repo push yourSpecs xxx.podspec –allow-warnings
  • 10. Check versions and files in local and remote directories
    • ~/.cocoapods/repos/yourSpecs

Common mistakes

The official CocoaPods issues

Common abnormal

  • Include of non-Modular header inside Framework Module

    • Solutions:
      • 1. Check the umbrella. H header file
      • Select the. H file in the project navigator. In the target membership area on the right there is a drop down menu next to the target. Select “public” there (probably “project” is selected right now).
      • 3. Set Allow non-modular Includes In Framework Modules to YES In Buldsetting all
  • Specs satisfying the xxxKit dependency were found, but they required a higher minimum deployment target.

    • Solution: Platform :ios, ‘8.2’ change the version number
  • Specification does not validate pod repo push yourSpecs

    • A: Allow-warnings
  • ERROR | [iOS] file patterns: The source_files pattern did not match any file.

    • Reference links into the corresponding folder, create a folder with source_files file path corresponding (~ / Library/Caches/CocoaPods/Pods/External/ProjectName / 035 cb9aa62b9d49f904fad1119b8)
  • pod repo push yourSpecs testLib.podspec: No such file or directory

    • pod repo push yourSpecs testLib.podspec –verbose –use-libraries –allow-warnings

reference

wtlucky’s Blog

Official Configuration Description