我正在为 iOS 应用程序创建一个静态库。我快完成了,但是资源有问题。
我的静态库使用了大量图像和声音文件。如何将它与我的静态库一起传输?
我知道我们可以将其打包并与 .a 文件一起提供。但我不知道如何将图像和声音文件包装在 Bundle 文件中。
我做了什么:
Settings Bundle 之外的任何包类型。最佳答案
有几个很好的理由来构建具有多个 bundle 的应用程序和几种不同的方法。根据我的经验,最好的方法是打开 Xcode 并创建一个新的 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 - How to transfer resource files with Static Library (How to wrap resources in bundle)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16297696/