Cocoapod bundle not available in my app

1k views Asked by At

I'm creating my own pod with some resources files. It is basically defined like this :

Pod::Spec.new do |s|
s.name         = 'MyName'
s.version      = '0.0.1'
s.license      =  { :type => 'MIT' }
s.homepage     = 'not important'
s.authors      = {
    # authors
}
s.summary      = '…'

# Source Info
s.source       =  {
    # .. my sources
}
s.source_files = ['Sources/*.swift']

s.resource_bundle = {'MyNameBundle' => ['*.{storyboard,xib,png,jsbundle,meta}']}

s.ios.deployment_target = '9.0'

s.requires_arc = true

end

The pod is installed with pod install and I can see that the resources files are available in MyName/Resources/. So far so good.

I can even see in my Pods.pbxcodeproj that there are 2 new targets : MyName and MyNameBundle-Bundle.

But the thing is, when I try to list all the available bundles :

        NSBundle.allBundles().forEach { 
           print("bundle identifier: \($0.bundleIdentifier) - path \($0.bundlePath)") 
        }

Then it does not show up.

What am I missing ?

1

There are 1 answers

0
aimak On BEST ANSWER

Well, here is an answer but I can't really explain how it works. If somebody has any idea, please let me know.

This post helped me a lot https://stackoverflow.com/a/35903720/1427775

So in my Pod, I had to add an empty swift class so that it could be used to load the correct NSBundle

let refreshBundle = NSBundle(forClass: MyEmptyClass.self)
    let bundleURL = newBundle.resourceURL?.URLByAppendingPathComponent("MyBundle.bundle")

    let bundle = NSBundle(URL: bundleURL!)!

It seems that not all NSBundle are loaded at launch and this code triggers the loading of the wanted bundle.