Cocoapods - Create pod for a private iOS repository

Viewed 3025

I have a repo with code which I do not want to share with others. But I want to have a pod which others can integrate in their applications. Is that possible ? I followed this tutorial but got the error on trying to add this on a different system : Unable to find specification for 'pod_name'.
Here is the pod file :

# Uncomment the next line to define a global platform for your project
#platform :ios, '9.0'

source 'https://github.com/my_source_url'

target 'DemoPods' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

 # Pods for DemoPods

pod 'MyPodName'

end  

My use case :

  • Keep my repository private so that source code can't be accessed.
  • Create Pod for my private repo.
  • Other users should be able to add the pod in their projects.
2 Answers

To distribute a closed source pod you first need to modify your private repository so that you can produce a .xcframework file.

Distribute through a URL

You have to zip the .xcframework file and make it available through a URL to your audience. (whether this is public or private)

Then you can create a .podspec file like this:

Pod::Spec.new do |s|
    s.name = '<POD_NAME>'
    s.version = '<VERSION>'
    s.summary = '<SUMMARY>'
    s.description = <<-DESC
    <DESCRIPTION>
                         DESC
  
    s.homepage = '<A_URL_TO_A_WEBPAGE>'
    s.author = { '<AUTHOR_NAME>' => '<AUTHOR_EMAIL>' }
    s.source = { :http => '<URL_TO_YOUR_ZIP_FILE>' }

    ...

    s.vendored_frameworks = '<PATH_OF_XCFRAMEWORK_FILE_IN_THE_ZIP>.xcframework'
end

After that there are 2 methods to distribute it:

  • Public: If you want to distribute your pod through cocoapods specs repo, you can push your .podspec file to the cocoapods trunk following this guide:

    pod trunk push <PATH_TO_YOUR_PODSPEC_FILE>.podspec
    

    The installation from the users will be like any other pod:

    use_frameworks!
    
    target 'TargetName' do
      pod '<POD_NAME>'
    end
    

    Private: For private distribution follow this quide, create a private specs repo and use the following command to push your podspec:

    pod repo push <REPO_NAME> <PATH_TO_YOUR_PODSPEC_FILE>.podspec
    

    The installation from the users will be like this:

    use_frameworks!
    
    target 'TargetName' do
      pod '<POD_NAME>', :source => '<PRIVATE_SPECS_REPO_URL>'
    end
    
  • Public: If you don't mind about cocoapods specs repo (or if you want to test your .podspec file) you can make your .podspec file publicly available through a URL and then instruct the users to use the podspec way in their Podfile to install your pod:

    use_frameworks!
    
    target 'TargetName' do
      pod '<POD_NAME>', podspec: '<URL_TO_YOUR_PODSPEC_FILE>.podspec'
    end
    

    Private: The same method also applies to the private distribution, as long as your users are the only ones that known or have access to the podspec URL.

Distribute through a Github repo

Although I don't recommend committing a binary file (which is the .xcframework) into a git repo, you can pretty much do the same using a git repo but without the need to zip your .xcframework file.

Create a git repository and add the .xcframework file along with a .podspec file like this:

Pod::Spec.new do |s|
    s.name = '<POD_NAME>'
    s.version = '<VERSION>'
    s.summary = '<SUMMARY>'
    s.description = <<-DESC
    <DESCRIPTION>
                         DESC
  
    s.homepage = '<A_URL_TO_A_WEBPAGE>'
    s.author = { '<AUTHOR_NAME>' => '<AUTHOR_EMAIL>' }
    s.source = { :git => '<URL_TO_YOUR_GIT_REPO>.git', :tag => s.version.to_s }

    ...

    s.vendored_frameworks = '<PATH_OF_XCFRAMEWORK_FILE_IN_THE_REPO>.xcframework'
end

Public: Then you can distribute your pod through cocoapods specs repo by pushing your .podspec file to the cocoapods trunk like this:

pod trunk push <PATH_TO_YOUR_PODSPEC_FILE>.podspec

Private: For private distribution, you can create a private specs repo and use the following command to push your podspec:

pod repo push <REPO_NAME> <PATH_TO_YOUR_PODSPEC_FILE>.podspec

If I understand your intentions correctly, you want to make your library public without opening the source code. In this case, you should check out the example of GoogleWebRTC. This is their pods config.

In this case, your cocoapod library would simply be a container for the built framework. For example, you can create a public repository, which will store the information needed for cocoapods and the built framework itself. I think It's even possible to configure github to publish builds from your private repo to the public one, but it may be a little bit challenging.

You can check out this guide

Related