3

I am trying to create a static framework which will use some images to show in its view. I have created a MyFrameworkBundle.bundle from XCode by adding the target in my sdk project. Added all my images in the bundle and created the bundle and gave that target a bundle identifier my.frameworkbundle. Now i am trying to fetch that bundle in my framework like following :

NSBundle * mybundleRef = [NSBundle bundleWithIdentifier:@"my.frameworkbundle"];

Then I put those framework and resource bundle in another project and tried to run function with above line. It always return null. Even if I try to fetch framework like above code i.e.:

NSBundle * mybundleRef = [NSBundle bundleWithIdentifier:@"my.framework"];

This also gave me null. But if I change this framework from static to dynamic it always gives me right bundle. As I am going to use it with Unity so I don't want a dynamic framework to avoid post processing script.

I also tried the following code :

NSString *bundleString =[[NSBundle mainBundle] pathForResource:@"MyFrameworkBundle" ofType:@"bundle"];
NSBundle * PlayCacheBundle = [NSBundle bundleWithPath:bundleString];

but it gives error

no suitable image found

System Details:

  • Xcode : 8.2.1
  • MacOS : 10.12 (Sierra)
Anas iqbal
  • 1,036
  • 8
  • 23

2 Answers2

3

Because the framework is statically linked the classes seem to belong to the main bundle, thus +[NSBundle bundleForClass:] doesn't work.

You can create your own bundle pointing to the framework using the following:

NSString *fwPath = [[[NSBundle mainBundle] privateFrameworksPath] stringByAppendingPathComponent:@"Shared.framework"]; NSBundle *bundle = [NSBundle bundleWithPath:fwPath];

I have tested on an empty project, it works, and allows loading NIB files. I haven't tested asset catalogs but I suspect since this is a valid NSBundle reference you should be fine.

dvkch
  • 1,079
  • 1
  • 12
  • 20
0

Static libraries are just compilations of object files (multiple .o files in one .a file). Their identity disappears when they're linked into an executable target (app binary or dynamic library), and they bring no resources other than code and constant data.

shallowThought
  • 19,212
  • 9
  • 65
  • 112