5

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.
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Nitish
  • 13,845
  • 28
  • 135
  • 263

2 Answers2

7

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
gcharita
  • 7,729
  • 3
  • 20
  • 37
  • Aren't both the above methods ways to publicly distribute the framework ? I want the distribution to be private using pods. – Nitish Mar 04 '21 at 05:17
  • @Nitish sorry, the distribution audience wasn't so clear and I assumed that will be public. So, you want to distribute your pod **as a framework** and using a **private specs repo**? – gcharita Mar 04 '21 at 09:51
  • Yes, that's correct. Framework as a pod but with private repo. – Nitish Mar 04 '21 at 09:56
  • @Nitish in that case you can definitely use the second method but without pushing to the cocoapods trunk. I am checking if the first also works. – gcharita Mar 04 '21 at 10:06
  • In this link it's mentioned [here](https://success.mirantis.com/article/can-other-users-search-and-view-my-private-repositories) that we need to add the users on git to whom we want to provide the access (if we have a pod). I am not sure if this would be feasible solution considering I don't want to add the user on git overtime a new user wants to use my library. – Nitish Mar 04 '21 at 10:40
  • @Nitish yes, but that's the point of private distribution of a pod, to have complete control of the users that have access to your pod. Sorry if I missed something. – gcharita Mar 04 '21 at 11:19
  • @gcharita if source url is private and podspec is public , is there anyway to prompt for password via Cocoapods? – Parag Bafna Feb 15 '22 at 14:14
  • 1
    @ParagBafna I just tested that using the **podspec** way of my answer. You can add this line `pod '', podspec: '.podspec'` in your `Podfile`. (with `URL_TO_YOUR_PODSPEC_FILE` be a public URL) Then, when you run `pod install` in terminal, you will be asked to insert the private repository credentials. (unless they already exist in the keychain) – gcharita Feb 15 '22 at 15:04
  • @gcharita Thanks. My source is http and on pod install its failing with "curl: (22) The requested URL returned error: 403". My podspec is public but framework is private – Parag Bafna Feb 15 '22 at 16:13
  • 1
    I am not using git repo for hosting .zip file – Parag Bafna Feb 15 '22 at 16:21
  • 1
    @ParagBafna oh now I see. You are probably using http authentication for your .zip file. The issue with `curl` and the option `-n` has been fixed. (just tested with the latest cocoapods version) Check [this](https://github.com/CocoaPods/CocoaPods/issues/5055) issue. So, you can use an `.netrc` file in your home direcroty with your credentials. – gcharita Feb 15 '22 at 21:17
1

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

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
  • But the code is public. I can see the source code. – Nitish Mar 05 '21 at 11:40
  • If you're talking about a pods config link I've included, it's a pod config file in the cocoapods repository - it contains configs for all public pods. As usually you only mention a name in your podfile, there need to be a source of truth. This particular config only contains a link to a built GoogleWebRTC.framework (https://dl.google.com/dl/cpdc/eae5bee0861b6f47/GoogleWebRTC-1.1.31999.tar.gz"), and doesn't have the source code. I've added a link to a guide on how make such pod. – Phil Dukhov Mar 05 '21 at 20:16