Search code examples
iosxcodensbundleios-frameworks

NSBundle bundleWithIdentifier returning null for Static framework and resource bundle


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)

Solution

  • 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.