[Cocoapods]: Resource Bundle not accessbile

Before loading resources with podspec:

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

Now I tried to do the same with the following:

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

They seem to be copied since I can find them under:

Pods\Development Pods\MyFramework\Resources

But when I try to download them:

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

testImage always nil.

I also tried to find out if there was any package available, so I would need to load the image from the created package, but:

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

It was revealed that through Cocoapods not a single package was created.

How can I access these resources?

+5
source share
2 answers

Resources are placed in a package called "Resources".

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

you can access the package using the following code

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

The key in s.resource_bundles is the name of the package.

Note: I have several packages listed in the following code. You may have other problems in the settings of your module. NSArray * bundles = [[NSBundle mainBundle] pathsForResourcesOfType: @ "bundle" inDirectory: nil];

0
source

To load an image from a package, use:

 UIImage *testImage = [UIImage imageNamed:@"Resources.bundle/testImage.jpeg"]; 
0
source

Source: https://habr.com/ru/post/1200741/


All Articles