Reputation: 71
What are the steps to follow to create and publish a pod in cocoapods?
Upvotes: 0
Views: 1649
Reputation: 71
Prerequisite: Pod should be installed.
Run the following commands in the terminal to install cocoapod.
Sudo gem install cocoapods
Check if installation is successful by running the command.
pod --version
Official cocoapods installation guide
Installation troubleshooting
Steps:
First we have to create an xcode framework that to be hosted in Cocoapods.org.
To share the framework functionalities to the public, that is, to be accessible outside the module, we have to make the classes, structures, methods of the framework public.
Then, we have to push the framework to github.
Create a github tag (Version number) and push the tag.
We have to create a podspec locally and later (step 8) upload it in the same github directory of the framework. To create a podspec locally run terminal command: pod spec create FrameworkName
Describe the podspec file accordingly. Podspec guide
Example podspec:
Pod::Spec.new do |spec|
spec.name = 'Reachability' # name of the framework
spec.version = '3.1.0' # same as github tag version
spec.license = { :type => 'BSD' } # can be :type=> ‘MIT’
spec.homepage = 'https://github.com/tonymillion/Reachability' # Website with details about pod or github repository link
spec.authors = { 'Tony Million' => '[email protected]' } # name & email address of the framework author
spec.platform = :ios, "13.0"
spec.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X.'
spec.source = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' } # url to clone the framework, tag may be same as spec.version
spec.source_files = 'Reachability.{h,m}' # add the regex to access all the files for the framework ex: ‘FrameworkName/**/*.{h,m,swift}’
end
Save the podspec and then test (lint) the podspec.
Terminal command: pod spec lint
Warnings can be allowed: pod spec lint --allow-warnings
After the podspec passes validation, update the remote repository by pushing the podspec to github repository. (add -> commit -> push)
To upload the pod in cocoapods.org to be accessible publicly, we have create a pod session. For this, first we have to register to cocoapods if we are not registered yet.
Terminal command: pod trunk register email username --description=’macbook pro’
Then a verification email will be sent to us that we have to verify.
Create the session. Terminal command: pod trunk me
Then we will push the pod. Terminal command: pod trunk push FrameworkName.podspec
Warnings can be allowed : pod trunk push FrameworkName.podspec --allow-warnings
It will validate (lint) the podspec file.
It will show a success message if everything goes right with a cocoapods.org link of the framework.
Push the updated local repository to the remote repository. (add -> commit -> push)
Following the URL we get from “12”, we can see our framework being hosted in cocoapods.org
Upvotes: 2