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
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With