Error loading png from .bundle to Objective-c

I am creating a framework in my Xcode project. To create the structure, I created a common goal. The structure consists of a static library, header files and the package .png assets, MyFrameworkResources.bundle . When I create an aggregate, everything is successfully created, and the package exists in my Products directory.

Also in my Xcode project there is a target application. This application is intended for testing framework products (static library, header files and package). I added a static library and MyFrameworkResources.bundle to the target dependencies of the target application. I also added MyFrameworkResources.bundle to copy the Bundle resources in the build phases of the target application.

I can use all the files from the static library just fine, but when I try to load resources from the package, I get an error. This is how I load assets from the package:

 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 register a package, I get the following:

bundle: Support NSBundle / Users / my_comp / Library / Application / iPhone Simulator / 6.1 / Applications / blah blah blah / MyApp.app / MyFrameworkResources.bundle (not yet loaded)

When I log an error, I get the following:

error: Domain error = NSCocoaErrorDomain Code = 4 "The package MyFrameworkResources could not be loaded because its executable file could not be found." UserInfo = 0x7535ee0 {NSLocalizedRecoverySuggestion = Try reinstalling the package., NSLocalizedFailureReason = Executable bundles could not be located., NSLocalizedDescription = The bundle "MyFrameworkResources" could not be loaded because its executable could not be located., NSBundlePath Library / Application Support / iPhone Simulator / 6.1 / Applications / blah-blah-blah / MyApp.app / MyFrameworkResources.bundle}

So, to double check, I cd'd in /Users/my_comp/Library/Application Support/iPhone Simulator/6.1/Applications/blah-blah-blah/MyApp.app/ on my computer, and MyFrameworkResources.bundle is actually there . So now I'm at a loss. I tried to clear the cumulative goal, clear the target application, delete the target application and no luck.

Any idea why I cannot load images from a package? (sorry for the long description)

Fyi, I use this great tutorial as a guide for creating frames and layering.

+4
source share
1 answer

Ah, after the battle for this a bit more, I came to MyFrameworkResources.bundle to double check that all assets were included. It turns out that Xcode renamed .png files to .tiff files and deleted retina assets. After further research, I found that Xcode automatically merges retina and non-retina .png files into "one multi-page TIFF . " Here is the link .

Solution, use ofType:@"tiff" instead of ofType:@"png" :

 UIImage *image = [UIImage imageWithContentsOfFile:[frameworkBundle pathForResource:@"AnyImage" ofType:@"tiff"]]; 
+6
source

All Articles