5

Before I was loading me resources with the podspec:

s.resources = ["MyFramework/Resources/**/*.{xib, png, jpeg, jpg}"]

now I tried to accomplish the same with the following:

s.resource_bundles = {'Resources' => ['MyFramework/Resources/**/*.{xib, png, jpeg, jpg}']}

They appear to be copied as I can find them under:

Pods\Development Pods\MyFramework\Resources

But when I try to load them:

UIImage *testImage = [UIImage imageNamed:@"testImage.jpeg"];

the testImage is always nil.

I also tried to find out if there was somehow a bundle accessible so I would need to load an image from a created bundle but:

NSArray *bundles = [[NSBundle mainBundle] pathsForResourcesOfType:@"bundle" inDirectory:nil];

Revealed that no bundle was created through Cocoapods.

How exactly can I access those resources?

Aranir
  • 828
  • 1
  • 10
  • 21

2 Answers2

0

The resources is put in a bundle called 'Resources'.

s.resource_bundles = {'Resources' => ['MyFramework/Resources/**/*.{xib, png, jpeg, jpg}']}

you can access the bundle by the following code

NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle]
                                                 pathForResource:@"Resources"      
                                                          ofType:@"bundle"]];

The key in the s.resource_bundles is the bundle name.

Note: I have some bundles listed by the following code. You may have other issues in your pod settings. NSArray *bundles = [[NSBundle mainBundle] pathsForResourcesOfType:@"bundle" inDirectory:nil];

Hai Feng Kao
  • 5,219
  • 2
  • 27
  • 38
0

To load an image from a bundle use:

UIImage *testImage = [UIImage imageNamed:@"Resources.bundle/testImage.jpeg"];
Ric Santos
  • 15,419
  • 6
  • 50
  • 75