Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundle(identifier: "org.cocoapods.MyPrivatePod") return nil

I would like to access to my private pod bundle, but always return nil.

Bundle(identifier: "org.cocoapods.MyPrivatePod")//only this return nil
Bundle(identifier: "org.cocoapods.Alamofire")
Bundle(identifier: "org.cocoapods.SQLCipher")

My podspec

Pod::Spec.new do |s|
  s.name                  = 'MyPrivatePod'
  s.version               = '1.4.0'
  s.summary               = 'MyPrivatePod Component'
  s.description           = "MyPrivatePod."
  s.homepage              = 'https://github.com/myprivatecompany/myprivtepodrepo.git'
  s.license               = ""
  s.authors               = { 'me me' => '[email protected]' }
  s.swift_version         = '4.2'
  s.source                = { :git => "[email protected]:myprivatecompany/myprivtepodrepo.git", :tag => "#{s.version}" }
  s.ios.deployment_target = '9.0'
  s.source_files          = 'MyPrivatePod/**/*.{h,m,swift}'
  s.resource_bundles      = {
    "MyPrivatePod" => ['MyPrivatePod/**/*.{xcassets,ttf,strings,json,xib,gif,storyboard}']
    }
  #s.resources        = 'MyPrivatePod/**/*.{xcassets,ttf,strings,json,xib,storyboard}'
  s.static_framework      = true
  s.dependency 'AnotherPrivatePod', '2.3.0'
end
like image 368
Ricardo Avatar asked Dec 04 '19 22:12

Ricardo


2 Answers

The problem is that you are defining MyPrivatePod as a static framework in your podspec:

s.static_framework      = true

When you use a static framework the compiler will include the code you need from that framework in your app binary and won't bundle that framework in the app package. This means that in run time there won't be any difference between the code in your app and the code in the framework.

Since this is the case, using something like:

let podBundle = Bundle(for: SomeClassFromPod.self)

will actually return the app bundle, because SomeClassFromPod was included as as part of the app binary at compile time.

If you only include code in your framework, I can't think of any use case for needing a reference to that bundle. If you also include some resources other than the code, you have two options to access them:

  1. Build and include your framework as a dynamic framework. The drawback of doing this is that you will incur in the performance issues at app launch time associated to including dynamic frameworks.
  2. Continue using the framework as a static framework and manually copy the resources in that framework to your app bundle. You can do this by adding a New Copy Files Phase in the build phases of your main app (You need to do this only when including the framework manually). After doing this you can access those resources as you would do if they belonged to your main bundle in the first place. The problem with doing this is that resources with the same name in different bundles would collide.
like image 148
Reynaldo Aguilar Avatar answered Nov 15 '22 05:11

Reynaldo Aguilar


I would try a different approach, you can request a Bundle(for aClass:) so if you grab any class from your pod, you can simply get your bundle using this code:

let podBundle = Bundle(for: SomeClassFromPod.self)

Very often it is useful to create an empty class in the library dedicated for locating a bundle, it is usually called BundleToken so you then use this:

let podBundle = Bundle(for: BundleToken.self)

But if you insist on using the Bundle(identifier:) approach, then I think that you pod has different bundle identifier than org.cocoapods.MyPrivatePod, so the SDK cannot find it. You will find the bundle identifier of your pod in the Xcode project just as you would do for any other app/library.

like image 35
olejnjak Avatar answered Nov 15 '22 06:11

olejnjak