How to transfer resource files with a static library (how to wrap resources in a package)?


I am creating a Static Library application for iOS . I almost completed it, but the problem is with the resources.

My static library uses a lot of images and sound files. How can I transfer it to my static library?

I know that we can wrap it in a bunch and pass it through the .a file. But I do not know how to wrap images and sound files in a bundle file.

What I've done:

  • I searched a lot, but did not find any useful links.
  • I got the Conceptual CFBundles link, but could not find a solution to my problem.
  • I checked the file templates available for Xcode, but did not see any types of packages other than the Settings Bundle.
+8
ios resources bundle static-libraries nsbundle
source share
1 answer

There are several good reasons to create an application with several packages and several different ways. In my experience, the best way is to open Xcode and create a new package project:

  • Choose: File → New Project ... → Mac OSX Group (!) → Frame and Library → Package. Add your resource files to the project.
  • Build the package while creating other iPhone apps.
  • You can add this project to your static library project and rebuild it all the time when the library is modified. You should be aware that the package itself will not be associated with your library file.
  • In application projects, add the .bundle file to your project as a regular resource file (Add → Existing Files ... → find and select the add-on .bundle file. Do not copy it).

Example:

 // Static library code: #define MYBUNDLE_NAME @"MyResources.bundle" #define MYBUNDLE_IDENTIFIER @"eu.oaktree-ce.MyResources" #define MYBUNDLE_PATH [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: MYBUNDLE_NAME] #define MYBUNDLE [NSBundle bundleWithPath: MYBUNDLE_PATH] // Get an image file from your "static library" bundle: - (NSString *) getMyBundlePathFor: (NSString *) filename { NSBundle *libBundle = MYBUNDLE; if( libBundle && filename ){ return [[libBundle resourcePath] stringByAppendingPathComponent: filename]; } return nil; } // ..... // Get an image file named info.png from the custom bundle UIImage *imageFromMyBundle = [UIImage imageWithContentsOfFile: [self getMyBundlePathFor: @"info.png"] ]; 

For more help you can check out these good articles.

Hope this helps you.

+9
source share

All Articles