I'm building a framework in my Xcode project. To build the framework, I created an aggregate target. The framework consists of the static library, header files, and bundle of .png assets, MyFrameworkResources.bundle
. When I build the aggregate, everything is successfully created and the bundle exists in my Products directory.
Also in my Xcode project is a target Application. This application is for testing the framework products (static library, header files, and bundle). I've added the static library and MyFrameworkResources.bundle
to the Target Dependencies of the target Application. I've also added MyFrameworkResources.bundle
to Copy Bundle Resources in Build Phases of the target Application.
I can use all files from the static library just fine, but I get an error when trying to load resources from the bundle. This is how I'm loading assets from the bundle:
NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath];
NSString *frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:@"MyFrameworkResources.bundle"];
NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
NSLog(@"bundle: %@", frameworkBundle);
NSError *error;
[frameworkBundle loadAndReturnError:&error]; // <-- THIS RETURNS AN ERROR
NSLog(@"error: %@", error);
UIImage *image = [UIImage imageWithContentsOfFile:[frameworkBundle pathForResource:@"AnyImage" ofType:@"tiff"]]; // <-- EDIT, USE "tiff", NOT "png"
When I log the bundle, I get this:
bundle: NSBundle /Users/my_comp/Library/Application Support/iPhone Simulator/6.1/Applications/blah-blah-blah/MyApp.app/MyFrameworkResources.bundle (not yet loaded)
When I log the error, I get this:
error: Error Domain=NSCocoaErrorDomain Code=4 "The bundle “MyFrameworkResources” couldn’t be loaded because its executable couldn’t be located." UserInfo=0x7535ee0 {NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSLocalizedFailureReason=The bundle’s executable couldn’t be located., NSLocalizedDescription=The bundle “MyFrameworkResources” couldn’t be loaded because its executable couldn’t be located., NSBundlePath=/Users/my_comp/Library/Application Support/iPhone Simulator/6.1/Applications/blah-blah-blah/MyApp.app/MyFrameworkResources.bundle}
So to double check, I cd'd into /Users/my_comp/Library/Application Support/iPhone Simulator/6.1/Applications/blah-blah-blah/MyApp.app/
on my computer, and the MyFrameworkResources.bundle
was actually there. So now I'm at a loss. I've tried cleaning the aggregate target, cleaning the target Application, deleting the target Application, and no luck.
Any idea why I can't load images from the bundle? (sorry for the lengthy description)
Fyi, I've been using this great tutorial as a guideline to build the framework and bundle.