Deploying iOS Libraries to CocoaPods
CocoaPods is a dependency manager that is used to run Objective C, Swift, and some other languages under the Objective C runtime. Like Gradle for Android, CocoaPods is also an architecture that helps to integrate dependencies and libraries much easier in your iOS project.
In this article, I will show how to publish an iOS library to CocoaPods.
Requirements
- You need to have access to an iOS library
- The iOS library should be pushed to a Git repository(GitHub, Gitlab, Self-hosted, …)
In this example, I will be using this repo.
Registering a Session for your Machine
If you have not registered for a session before on the machine that you are using for pushing the pod, you should else you will get an error as shown below.
[!] You need to register for a session first.
So to register for a session, you should use your email, name and the name/description of the deployment machine as shown below.
pod trunk register [email] '[name]' --description='[name/description of the deployment machine]'
pod trunk register zafir@zfir.dev 'Zafir' --description='Macbook Pro M1 14 Inch'
Pushing your Pod
Before pushing to Cocoapods, you need to modify the podspec file. An example of the podsc file is shown below.
Pod::Spec.new do |s|
s.name = 'JPSVolumeButtonHandler@SpoonConsulting'
s.version = '1.0.4'
s.platform = :ios, "7.0"
s.license = 'MIT'
s.summary = 'JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps!'
s.homepage = 'https://github.com/spoonconsulting/JPSVolumeButtonHandler'
s.author = { 'SharinPix Admin' => 'admin@sharinpix.com', 'Zafir Sk Heerah' => 'zafir.heerah@spoonconsulting.com', 'JP Simard' => 'jp@jpsim.com' }
s.source = { :git => 'https://github.com/spoonconsulting/JPSVolumeButtonHandler.git', :tag => s.version.to_s }
s.description = 'JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps! Features:\n* Run blocks whenever a hardware volume button is pressed\n* Volume button presses don\'t affect system audio\n* Hide the HUD typically displayed on volume button presses\n* Works even when the system audio level is at its maximum or minimum, even when muted'
s.source_files = 'JPSVolumeButtonHandler@SpoonConsulting/*.{h,m}'
s.framework = 'MediaPlayer', 'AVFoundation'
s.requires_arc = true
end
In this file, you should change the version to the correct one as this version is the one that is going to be published.
s.version = '1.0.4'
You are also required to create a tag with the version on the remote repository.
git tag [version]
git push --tags
git tag 1.0.4
git push --tags
Once all these configurations are done, you can use the command below to push the pod.
pod trunk push
You should get a successful output as shown below:
Updating spec repo `trunk`
--------------------------------------------------------------------------------
🎉 Congrats
🚀 JPSVolumeButtonHandler@SpoonConsulting (1.0.4) successfully published
📅 November 5th, 12:16
🌎 https://cocoapods.org/pods/JPSVolumeButtonHandler@SpoonConsulting
👍 Tell your friends!
--------------------------------------------------------------------------------