使用多个捆绑包和几种不同的方法来构建应用程序有几个很好的理由。根据我的经验,最好的方法是打开 Xcode 并创建一个新的捆绑项目:
- 选择:文件 -> 新项目... -> 组 Mac OSX (!) -> 框架和库 -> 捆绑包。将您的资源文件添加到项目中。
- 在构建其他 iPhone 应用程序时构建捆绑包。
- 您可以将此项目添加到您的静态库项目中,并在库更改时重新构建它。您必须知道捆绑包本身不会链接到您的库文件。
- 在您的应用项目中,将 .bundle 文件作为普通资源文件添加到您的项目中(添加 -> 现有文件... -> 找到并选择上面构建的 .bundle 文件。不要复制它)。
例子 :
// 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"] ];
如需更多帮助,您可以查看这些好文章
iOS 资源库
资源包
希望它可以帮助你。