[英]How to transfer resource files with Static Library (How to wrap resources in bundle)?
我正在为iOS
应用程序创建一个Static Library
。 我几乎完成了它,但是资源存在问题。
我的静态库使用了大量的图像和声音文件。 如何使用我的静态库传输它?
我知道我们可以将它包装在一个包上并沿着.a
文件提供它。 但我不知道如何将图像和声音文件包装在Bundle文件中。
我做了什么:
Settings Bundle.
之外的任何bundle类型Settings Bundle.
使用多个捆绑包和几种不同的方法来构建应用程序有几个很好的理由。 根据我的经验,最好的方法是打开Xcode并创建一个新的捆绑项目:
示例:
// 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"] ];
如需更多帮助,您可以查看这些好文章
希望它能帮到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.